[plt-scheme] How to define C-structure type with bit fields using FFI?
I dont know if it will help you a whole lot but I binded scheme to sdl a
while ago. Attached is my somewhat incomplete version but you can steal
whatever you like. I did something like what Eli wrote below for the
video flags.
BTW, SDL by itself is very primitive and you will need another C library
to do any real work( like drawing lines ). There are other libraries
built on top of SDL to do this but I quickly abandoned SDL for a
higher-level library, allegro: http://alleg.sf.net. The bindings are
available via planet:
http://planet.plt-scheme.org/#allegro.plt
I have a cheesy game using the sdl bindings too, abm, if you are interested.
Eli Barzilay wrote:
> On Sep 26, Nikolay Artamonov wrote:
>
>> Hi all!
>>
>> Is it possible to define C-structure type, using FFI, for structure
>> with bit fields?
>>
>
> No.
>
>
>
>> For example, we have this structure in C-side:
>>
>> typedef struct{
>> Uint32 hw_available:1;
>> Uint32 wm_available:1;
>> Uint32 blit_hw:1;
>> Uint32 blit_hw_CC:1;
>> Uint32 blit_hw_A:1;
>> Uint32 blit_sw:1;
>> Uint32 blit_sw_CC:1;
>> Uint32 blit_sw_A:1;
>> Uint32 blit_fill;
>> Uint32 video_mem;
>> SDL_PixelFormat *vfmt;
>> } SDL_VideoInfo;
>>
>> (This is real structure from SDL library - http://www.libsdl.org)
>>
>> And how we can express that structure in our Scheme-wrapper with,
>> for example, define-cstruct? Are there direct ways for it, or we
>> should write some auxiliary C-code or even MzScheme extension?
>>
>
> You need to specify the actual representation (I'm not sure if C will
> use a char or an int for that), then deal with number in Scheme using
> the bitwise functions. The above case looks particularly simple -- it
> looks like you can use the _bitmask type to represent the field as a
> list of up to 8 symbols.
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sdl.ss.gz
Type: application/gzip
Size: 7797 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20060926/6cd038f4/attachment.bin>