[Ecls-list] Accessing Lisp Structures in C code

Jeremy Shoemaker jeremy at codingkoi.com
Thu Nov 15 21:10:42 UTC 2007


Hi,
  I've been messing around with embedding Lisp into a C application
and I've run into some trouble with the fact that the documentation
isn't exactly complete.
  I'm basically using the C application for all of the low-level code
and to ease access to external libraries and using Lisp for all of the
application logic.  My problem is that I have a few C functions in
which I'd like to access and return a Lisp structure or class to the
Lisp side of things, but I don't know how to construct it in C.
  An example would be the following (and I know this example would be
easier to write in plain Lisp, but suppose that something I did on the
C side required some library function call or needed to be really fast
or something):

Suppose I have a structure for a vector (math vector) defined in Lisp as:

(defstruct vec x y z)

And I have a function exposed from C called `x-product' that computes
the cross product.  I would probably define it like this:

cl_object x_product(cl_object lhs, cl_object rhs) {
  /* compute the cross production */
  /* return a new vec holding the value of the product */
}

a) How do I access the fields of the two `vec's passed in?
-and-
b) How do I construct a new `vec' in C?  And better yet, how could I
do it if I wanted to return a class instead of a structure?

I hope that makes sense.  Thanks in advance, and I apologize if this
has been asked before, I couldn't find anything about it in the
archives.

Jeremy Shoemaker




More information about the ecl-devel mailing list