More detailed embedding example

Daniel Kochmański daniel at turtleware.eu
Mon Sep 28 06:57:55 UTC 2015


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

-- 
Daniel Kochmański | Poznań, Poland
;; aka jackdaniel

"Be the change that you wish to see in the world." - Mahatma Gandhi



More information about the ecl-devel mailing list