[Ecls-list] Exposing C Structs to Lisp

Scott Rallya srallya at gmail.com
Mon Mar 1 04:05:06 UTC 2010


One of my side projects is trying to embed ECL within a MUD
(Multi-user dungeon). The MUD is written in C, and I'm trying to
expose a C struct to Lisp representing a character. I *am*  using CFFI
and have defined the struct in Lisp with cffi:defcstruct. Furthermore,
I have a function written in Lisp

(defun do-say-impl (player txt)
  (cffi:with-foreign-object (player 'char_data)
                          (log-string (cffi:foreign-string-to-lisp

(cffi:foreign-slot-value player 'char_data 'name))))
  (send-to-char player txt))

Inside the C code itself, I have:
cl_object secl_player =
ecl_make_foreign_data(make_simple_base_string((char
*)":pointer"),sizeof(CHAR_DATA *),ch);
cl_funcall(2,c_string_to_object("do-say"), secl_player);

 "do-say" only calls "do-say-impl" with secl_player and the string "Testing".

If I add a (break) after the 'with-foreign-object' and try to inspect
the 'player' argument that was passed in, I see that it doesn't
actually
correspond to the instance of the struct I want to deal with (eg,
'player' is undefined). I've tried several approaches to the
ecl_make_foreign_data, but
I'm not quite sure if I'm doing things correctly. Furthermore, since I
know CFFI isn't standard in ECL I wasn't sure if I can expect to use
ecl_make_foreign_data and
then CFFI as well.

Any help, tips, or suggestions with this would be greatly appreciated.




More information about the ecl-devel mailing list