Hello! Has there been any more thought put into the possibility of defining an array type? Having read the list archives, I'm aware that this has been proposed:
http://common-lisp.net/pipermail/cffi-devel/2005-September/000057.html
I can certainly help test on various Lisp implementations, and with some guidance into how types are defined in CFFI, I'm willing to contribute some patches.
Thanks.
-- Jack Unrue
Jack Unrue jdunrue@gmail.com writes:
Hello! Has there been any more thought put into the possibility of defining an array type? Having read the list archives, I'm aware that this has been proposed:
Hello,
Can you give me an example usage of such type or an example that shows how the current array support is insufficient?
Thanks,
Hello,
Can you give me an example usage of such type or an example that shows how the current array support is insufficient?
Thanks, Luís. I may be misunderstanding what array support is already present. I'm looking for basically what you proposed in your reply to:
http://common-lisp.net/pipermail/cffi-devel/2005-September/000058.html
My goal is simply to declare structs whose C equivalent includes array members. I'm not sure how the array declaration would be done in CFFI so I'll use LispWorks FLI instead:
(fli:define-c-struct foo (data (:c-array :int 32)) (id :int))
would correspond to
struct foo { int data[32]; int id; };
such that allocating an instance of foo on the Lisp side could be accomplished without having to separately allocate the data array. In LispWorks, I would use fli:with-dynamic-foreign-objects to allocate a temporary instance of foo.
A real example of how I would use this is the Win32 BeginPaint function which populates a supplied pointer to a PAINTSTRUCT (which has a 32 byte array as the last member).
Thanks again, and if RTFM is the answer, please do point me in the right direction :-)
-- Jack Unrue
On 2005-dec-11, at 06:48, Jack Unrue wrote:
My goal is simply to declare structs whose C equivalent includes array members. I'm not sure how the array declaration would be done in CFFI so I'll use LispWorks FLI instead:
(fli:define-c-struct foo (data (:c-array :int 32)) (id :int))
This would translate to:
(cffi:defcstruct foo (data :int :count 32) (id :int))
The plan is that you would access an element of this array using (cffi:foreign-slot-value foo-obj 'foo 'data <index>). However, this is not implemented yet so, for the time being, you'll need to use something like:
(cffi:mem-aref (cffi:foreign-slot-value foo-obj 'foo 'data) :int <index>)
Or:
(cffi:with-foreign-slots ((data) foo-obj foo) (cffi:mem-aref data :int <index>))
This is not to say that an array type is not needed. I think we'll need one in order to access multi-dimensional arrays conveniently.
On 12/11/05, Luís Oliveira luismbo@gmail.com wrote:
This would translate to:
(cffi:defcstruct foo (data :int :count 32) (id :int))
Many thanks, that's what I was missing. And also thanks for the info about mem-aref.
-- Jack Unrue