[Ecls-list] embedding questions

Peter Keller psilord at cs.wisc.edu
Mon Dec 10 00:09:20 UTC 2012


Hello,

On Sun, Dec 09, 2012 at 12:04:30AM +0100, Juan Jose Garcia-Ripoll wrote:
> On Sat, Dec 8, 2012 at 7:27 PM, Peter Keller <psilord at cs.wisc.edu> wrote:
> Say for instance you need to create structures with two slots
> 
> * Evaluate a "(defstruct foo a b)" form at the outer part of your code
> (c_string_to_object + cl_eval)
> * Store global references to the symbols MAKE-FOO, :A and :B (this is safe,
> for symbols in packages are not garbage collected)
> * Define a simple C function that uses that symbol to invoke the structure
> creation.
> 
> const char *defstruct_form = "(defstruct cl-user::foo a b)"
> cl_object make_foo = ecl_read_from_cstring("cl-user::make-foo");
> cl_object keyword_a = ecl_make_keyword("A");
> cl_object keyword_a = ecl_make_keyword("B");
> 
> cl_object make_foo(int a, const char *b)
> {
>    return cl_funcall(5, make_foo, keyword_a, ecl_make_fixnum(a), keyword_b,
> ecl_make_constant_base_string(b, strlen(b)));
> }
> 
> int main () {
> ...
> cl_eval(1,ecl_read_from_cstring(defstruct_form));
> ...
> }

Thank you very much for your advice! 

For my initial version, it seems packing and unpacking the C data by hand
into and out of the lisp objects returned by the lisp code is something I
understand and seem to be able to make work. I believe there is a better
way, but I just need to hack a while and get some experience with the
various solutions before I feel confident in choosing something else. It
is just a learning process.

I had never been in the C API of ECL before in such a deeply embeded
fashion and it is a nice experience. One thing I particularly liked is
the :init-name keyword in C:BUILD-STATIC/SHARED-LIBRARY so I can predict
the initialization function name for read_VV(). That's excellent.

Thank you!

-pete




More information about the ecl-devel mailing list