[Ecls-list] Binding C/C++ Functions From Calling C/C++ Code
    Nikhilesh S 
    s.nikhilesh at gmail.com
       
    Thu Feb 19 05:58:56 UTC 2009
    
    
  
Hey! I'm new to using mailing lists, so I'm sorry if I'm doing something
wrong.
I wanted to ask whether there's any function in the ECL C library to
bind a C function from a program to a Lisp function. For example, I have
the following simple ECL interpretter:-
#include <iostream>
#include <string.h>
#include <ecl/ecl.h>
using namespace std;
int main(int argc, char **argv)
{
     cl_boot(argc, argv);
     char input[1024];
     while (true)
     {
 	cout << "> ";
 	cin.getline(input, 1024);
 	if (strcmp(input,"quit") == 0)
 	    break;
 	cl_pprint(1, cl_safe_eval(c_string_to_object(input), Cnil, OBJNULL));
 	cout << "\n\n";
     }
     cl_shutdown();
     return 0;
}
What I'd like to do is something like this:-
int add(int a, int b) { return a + b; }
...
cl_bind(&add, "c-add", /*min params*/ 1, /*max params*/ 1);
And then be able to 'eval' this Lisp code:-
"(c-add 2 3)"
Which should give 5.
Of course there may be more parameters to 'cl_bind' I may not thought
of.
Thanks,
nikki
    
    
More information about the ecl-devel
mailing list