[Ecls-list] Accessing Lisp Structures in C code
Juan Jose Garcia-Ripoll
jjgarcia at users.sourceforge.net
Sat Nov 24 18:34:23 UTC 2007
On Nov 24, 2007 6:12 PM, Jeremy Shoemaker <jeremy at codingkoi.com> wrote:
> How would I do it the other way? Are you suggesting doing something like
> writing a lisp expression in a C string and then using c_string_to_object?
Forget it. You now have too simple functions
extern cl_object ecl_slot_value(cl_object x, const char *slot);
extern cl_object ecl_slot_value_set(cl_object x, const char *slot, cl_object y);
They take structures or CLOS objects, a slot name in the form of a
string with an optional package prefix and a possible new value for
the slot. They are far from optimal and safe, but better than nothing.
They also seem to work, as shown here:
$ cat foo.lsp
(defun foo (x)
(ffi::c-inline (x) (t) t
"ecl_slot_value(#0,\"b\")" :one-liner t))
(defun faa (x y)
(ffi::c-inline (x y) (t t) t
"ecl_slot_value_set(#0,\"b\",#1)" :one-liner t))
(defstruct a b)
(defvar *a* (make-a :b 1))
(print *a*)
(print (foo *a*))
(faa *a* 2)
(print (foo *a*))
(quit)
$ ecl -q -compile foo.lsp
;;; Loading #P"/Users/jjgarcia/lib/ecl/cmp.fas"
;;; Loading #P"/Users/jjgarcia/lib/ecl/sysfun.lsp"
$ ecl -eval '(load "foo")'
;;; Loading #P"/Users/jjgarcia/src/common-lisp.net/ecl/build/foo.fas"
#S(A :B 1)
1
2
--
Facultad de Fisicas, Universidad Complutense,
Ciudad Universitaria s/n Madrid 28040 (Spain)
http://juanjose.garciaripoll.googlepages.com
More information about the ecl-devel
mailing list