Hey guys,
I'm playing around with embedding ECL into a C program. I've followed the blog post which was very useful, but as far as calling lisp functions, didn't really get beyond the cl_safe_eval type operations. I'd like to be able to get a handle to a specific lisp function, and call that function passing some arguments. What I've tried is basically this series of steps (omitting boot, shutdown, etc for brevity):
* cl_safe_eval some code doing (load "foo.lisp") // From the blog example, works fine * ecl_make_symbol("BAR", "CL-USER") // Quite sure this is where I'm going wrong * cl_funcall the symbol from step 2, which gives me this a few times before dropping to debugger: Condition of type: SIMPLE-ERROR 0 is an illegal frs index. No restarts available.
I'm sure step 2 is where I'm going wrong and the symbol I try to retrieve is not valid, thus the issue in step 3. Sorry if this is too basic a question, but could someone give me a working example of doing something like this?
Thanks, Morgan
Hey Morgan,
could you add the reference - which blog post? And post the actual code you used?
You can find sample C code here: https://github.com/earl-ducaine/stupid-ecl-tricks-1 with swank example. Also in git repository there is subdirectory examples/, although be aware that examples in directory embed/ are temporaliry broken wrt initializing ECL produced libraries[1].
Crude sample:
#include <stdio.h> #include <ecl/ecl.h>
int main (int argc, char **argv) { /* Initialize ECL */ cl_boot(argc, argv);
cl_eval(c_string_to_object("(format t "Hello world")"));
cl_shutdown(); return 0; }
Call to cl_load should look as follows (borrowed from Earl's tricks):
cl_object cl_start_swank_path = c_string_to_object("foo.lisp"); cl_object cl_load = ecl_make_symbol("LOAD","CL"); cl_funcall(2, cl_load, cl_start_swank_path);
Best regards, Daniel
[1] https://gitlab.com/embeddable-common-lisp/ecl/issues/177
Morgan Howe writes:
Hey guys,
I'm playing around with embedding ECL into a C program. I've followed the blog post which was very useful, but as far as calling lisp functions, didn't really get beyond the cl_safe_eval type operations. I'd like to be able to get a handle to a specific lisp function, and call that function passing some arguments. What I've tried is basically this series of steps (omitting boot, shutdown, etc for brevity):
- cl_safe_eval some code doing (load "foo.lisp") // From the blog
example, works fine
- ecl_make_symbol("BAR", "CL-USER") // Quite sure this is where I'm going wrong
- cl_funcall the symbol from step 2, which gives me this a few times
before dropping to debugger: Condition of type: SIMPLE-ERROR 0 is an illegal frs index. No restarts available.
I'm sure step 2 is where I'm going wrong and the symbol I try to retrieve is not valid, thus the issue in step 3. Sorry if this is too basic a question, but could someone give me a working example of doing something like this?
Thanks, Morgan
Hey Daniel,
On Mon, Sep 28, 2015 at 1:57 AM, Daniel Kochmański daniel@turtleware.eu wrote:
could you add the reference - which blog post? And post the actual code you used?
The blog post I was referring to was https://chriskohlhepp.wordpress.com/embedding-lisp-in-cplusplus-a-recipe/ which was linked somewhere in the ECL documentation, so I thought it might be somewhat of a canonical example. In any event, during the course of retyping and simplifying my testing code to provide you, I found that I made a stupid mistake. I have a series of different sets of iterative testing C source programs, some of which have their own corresponding lisp and others that share the same lisp code. Of course, I was loading the lisp code from the prior test iteration and so obviously, the function was not defined. I was traveling for around 20 hours over the weekend and actually did this while on the plane, so I blame it on the jet lag. :)
Thanks for your quick response and for your references, I will definitely check those out.
Regards, Morgan