On Sun, Aug 28, 2011 at 4:41 AM, Luís Oliveira luismbo@gmail.com wrote:
What kind of macro are you thinking of? In the COMPLEX case, do you want to abstract away the need to allocate (and free) the structure object explicitly?
I've written a macro define-structure-conversion to flesh out what I see as the way to go. Eventually, I think this would be best as a couple of key arguments in the defcstruct, similar to FSBV's current :constructor and :deconstructor arguments.
I am stuck however on recursive conversion of slots. What I have works for the complex example, but if I built on that with a "real-and-complex" structure and try to convert to foreign, I get an error because the complex slot is already converted by the time it gets in the setf. Even with an existing pointer, as would be obtained from foreign-slot-pointer, the only function I have at my disposal for translating the slot is translate-to-foreign which creates a new foreign struct, it does not write to an existing struct. It seems I need something like a setf function.
See the define-structure-conversion definition and test case exampleshttps://github.com/cffi/cffi/blob/4d475077a6c00dd12aa0fc72f8b36b8cb5b8c3d3/src/structures.lisp. Any thoughts on how to proceed?
Liam
-- Luís Oliveira http://r42.eu/~luis/