osdir.com
mailing list archive

Subject: Re: Including C struct definitions - msg#00164

List: lisp.scheme.chicken

Date: Prev Next Index Thread: Prev Next Index
> Nicolas Pelletier wrote:

>Hello,
>
>I am using Chicken 1.72 and would like to embed C structs in Scheme
>code. Some fields in these structures are themselves structued types,
>and csc gives an error on such structures.

Nikolas,

You might want to look at SWIG.

I just finished wrapping a couple of libraries, including SDL
(www.libsdl.org). SDL is a C library and the SDL event structure (a union
actually) might hold a keyboard event which has a nested keysym structure
and so on.

The structures were wrapped correctly for me although I added some custom
access functions for nested structure members, mostly for performance
reasons. Otherwise every time I try to access the nested structure a copy
of it is allocated and returned to me.

Thanks, Joel

--
OpenPoker: The Linux of poker software
http://wagerlabs.com/forums
Tenerife: Canary Islands: Spain


Was this page helpful?
Yes No
Thread at a glance:

Previous Message by Date: click to view message preview

Re: Including C struct definitions

On 20 Dec 2004 11:41:10 +0100, Nicolas Pelletier <nicolasp@xxxxxxxxxxxxxxxxxx> wrote: > Hello, > > I am using Chicken 1.72 and would like to embed C structs in Scheme > code. Some fields in these structures are themselves structued types, > and csc gives an error on such structures. Here is what my code looks > like: > > my_structs.scm: > #>! > #include "my_structs.h" > <# > > my_structs.h: > typedef struct > { > unsigned char a; > unsigned char b; > } a_t; > > typedef struct > { > a_t c; > unsigned long int d; > } b_t; > > csc gives the following error: > csc my_struct.scm -output-file my_struct.c > Error: invalid type specifier: (struct (scope (unsigned char (id "a")) > (unsigned char (id "b")))) > *** Shell command terminated with exit status 1: > /home/nicolasp/SunOS/chicken/bin/chicken struct.scm -output-file struct.c > -quiet -output-file struct.c > > I tried the following trick without success: > struct a_s > { > unsigned char a; > unsigned char b; > }; > typedef struct a_s a_t; > > struct b_s > { > struct a_s c; > unsigned long int d; > }; > typedef struct b_s b_t; > > This one chokes on the definition of the field called d. > > Is there a way to make this kind of structured types work ? > the easy ffi parser doesn't handle "long int", just use "long" in this case. Also, embedded structs are not handled. You would need to change the definition of "c" to be a pointer instead of a struct. (I will try to extend the FFI to handle these cases, though) cheers, felix

Next Message by Date: click to view message preview

darcs repo update

Oh, and the makefile problem should now be fixed as well. cheers, felix

Previous Message by Thread: click to view message preview

Re: Including C struct definitions

felix winkelmann <bunny351@xxxxxxxxx> writes: > > the easy ffi parser doesn't handle "long int", just use "long" in > this case. Also, embedded structs are not handled. You would need > to change the definition of "c" to be a pointer instead of a > struct. > (I will try to extend the FFI to handle these cases, though) Ok, thank you. I'll switch to using pointers, then. -- Nicolas

Next Message by Thread: click to view message preview

Re: Including C struct definitions

Joel Reymont <joelr@xxxxxxxx> writes: > > Nikolas, > > You might want to look at SWIG. SWIG is used to provide access to C functions (a lib or custom code) to a higher-level language, isn't it ? I am trying to achieve the converse: calling from C into Scheme and exchanging structures in both directions. The embedding capabilities of chicken help a lot here. I just hit a limitation of the current C parser provided by chicken when using nested structured types :-P But I did not know SWIG supported chicken... -- Nicolas
Sign up for updates to this mailing list. email:
Loading Comments...
Home | News | Patents | Sitemap | FAQ | advertise

Advertising by