Hi folks,
I'm trying to write an SDL (the graphics/sound gaming library)
application in Clisp, and I've managed to convert the header files okay,
with a bit of selective cutting and pasting and the use of ah2cl.lisp
(which seems to work!). I've got SDL to display a
window with this API information, but I can't figure out how to make an
SDL_Event to pass to the SDL_WaitEvent function.
Here's the converted header file info (without the individual structures
mentioned within):
;; /* General event structure */
(ffi:def-c-type SDL_Event (ffi:c-union (type Uint8) (active
SDL_ActiveEvent) (key SDL_KeyboardEvent) (motion SDL_MouseMotionEvent)
(button SDL_MouseButtonEvent) (jaxis SDL_JoyAxisEvent) (jball
SDL_JoyBallEvent) (jhat SDL_JoyHatEvent) (jbutton SDL_JoyButtonEvent)
(resize SDL_ResizeEvent) (expose SDL_ExposeEvent) (quit SDL_QuitEvent)
(user SDL_UserEvent) (syswm SDL_SysWMEvent)))
(ffi:def-call-out SDL_WaitEvent
(:library "sdl.dll")
(:name "SDL_WaitEvent")
(:return-type ffi:int)
(:arguments (event (ffi:c-ptr SDL_Event))))
Here's the relevant bit of the original header file:
/* If you want to use this event, you should include SDL_syswm.h */
struct SDL_SysWMmsg;
typedef struct SDL_SysWMmsg SDL_SysWMmsg;
typedef struct {
Uint8 type;
SDL_SysWMmsg *msg;
} SDL_SysWMEvent;
/* General event structure */
typedef union {
Uint8 type;
SDL_ActiveEvent active;
SDL_KeyboardEvent key;
SDL_MouseMotionEvent motion;
SDL_MouseButtonEvent button;
SDL_JoyAxisEvent jaxis;
SDL_JoyBallEvent jball;
SDL_JoyHatEvent jhat;
SDL_JoyButtonEvent jbutton;
SDL_ResizeEvent resize;
SDL_ExposeEvent expose;
SDL_QuitEvent quit;
SDL_UserEvent user;
SDL_SysWMEvent syswm;
} SDL_Event;
Here's my code that calls SDL:
(print (test:SDL_WaitEvent (test::make-sdl_event)))
And here's the error message I get:
*** - #S(TEST:SDL_EVENT :C-UNION NIL) cannot be converted to the foreign
type FFI:UCHAR
My question: I don't understand how to pass a new SDL_Event
union/structure to the SDL_WaitEvent call to be filled. I don't
understand why it thinks the union is a UCHAR (aka a Uint8, or an
unsigned char), when it's been defined as all of the above.
I think in C that a Union is the size of its highest entry, which
explains why it could be just one byte (the UCHAR).
The reason I want to use SDL with Clisp is that although I could use SDL
with Corman Common Lisp, there are other libraries related to SDL I need
to use, and Corman does not support these, and does not recognise FFI
files. I also prefer not to use a different Windows distribution of
Common Lisp per week, per application (for instance, the only way I could
find to get Aserve to run was on Lispworks). ;-)
Thanks for any help, I hope to make a website on using SDL with Clisp
when this is done.
Jeremy.
> (for instance, the only way I could
> find to get Aserve to run was on Lispworks). ;-)
Interesting... so AllegroServe doesn't work on Allegro Common Lisp
anymore? I suspect the folks at Franz aren't happy about that ;-)
> I hope to make a website on using SDL with
> Clisp when this is done.
I look forward to seeing that.
"Eric Lavigne" <············@gmail.com> wrote in
···························@g14g2000cwa.googlegroups.com:
>> (for instance, the only way I could
>> find to get Aserve to run was on Lispworks). ;-)
>
> Interesting... so AllegroServe doesn't work on Allegro Common Lisp
> anymore? I suspect the folks at Franz aren't happy about that ;-)
I was being slightly glib. The trial version doesn't have enough heap to
even load Aserve, but the Lispworks trial does (it's a stack-based
limitation). :-)
Jeremy.
From: Edi Weitz
Subject: Re: Clisp, FFI and SDL - trying to pass in a union to be filled
Date:
Message-ID: <ufynn0y8a.fsf@agharta.de>
On Tue, 17 Jan 2006 11:07:23 +0000 (UTC), Jeremy Smith <············@decompiler.org> wrote:
> I was being slightly glib. The trial version doesn't have enough
> heap to even load Aserve, but the Lispworks trial does (it's a
> stack-based limitation). :-)
Do you mean /Portable/ Aserve or Aserve? If it's the latter, then
it's quite amusing that Franz won't let you test that.
Cheers,
Edi.
--
Lisp is not dead, it just smells funny.
Real email: (replace (subseq ·········@agharta.de" 5) "edi")
Jeremy Smith wrote:
> I've got SDL to display a
> window with this API information, but I can't figure out how to make an
> SDL_Event to pass to the SDL_WaitEvent function.
>
Don't wait for events. Use SDL_PollEvent to retrieve all events in the
queue. Then process these, run your main game logic, redraw the screen
and call SDL_PollEvent again.
SDL_WaitEvent will wait indefinitely until an event appears, effectively
blocking your code from executing.
-Luke
Luke J Crook <····@REMOVE_THIS.balooga.com> wrote in
···························@giganews.com:
> Jeremy Smith wrote:
>
>> I've got SDL to display a
>> window with this API information, but I can't figure out how to make
>> an SDL_Event to pass to the SDL_WaitEvent function.
>>
> Don't wait for events. Use SDL_PollEvent to retrieve all events in the
> queue. Then process these, run your main game logic, redraw the screen
> and call SDL_PollEvent again.
>
> SDL_WaitEvent will wait indefinitely until an event appears,
> effectively
> blocking your code from executing.
>
> -Luke
Hi,
Thanks for the tip.
Just for the record, someone already did a page called "Corman Lisp FFI
Howto", which details getting it working with SDL, and, usefully enough,
says that the union is basically unliked by Lisp, so we replace it with
a uint8 and a 1024-byte buffer big enough for any part of the union!
Then you typecast the struct and its buffer to whatever event you need,
at runtime.
http://www.balooga.com/sdl_howto.php3
I didn't know about this page before I posted, but I found it while
looking for info on Corman's FFI functionality.
I guess we can consider the thread resolved.
Cheers,
Jeremy.
Jeremy Smith wrote:
> Just for the record, someone already did a page called "Corman Lisp FFI
> Howto",
That someone is me. Glad you found the page useful :)
-Luke
From: Edi Weitz
Subject: Re: Clisp, FFI and SDL - trying to pass in a union to be filled
Date:
Message-ID: <uy81ezy0i.fsf@agharta.de>
On Tue, 17 Jan 2006 15:07:46 +0000 (UTC), Jeremy Smith <············@decompiler.org> wrote:
> Just for the record, someone already did a page called "Corman Lisp
> FFI Howto", which details getting it working with SDL
For the record, this "someone" is the one you were replying to... :)
Cheers,
Edi.
--
Lisp is not dead, it just smells funny.
Real email: (replace (subseq ·········@agharta.de" 5) "edi")
From: Edi Weitz
Subject: Re: Clisp, FFI and SDL - trying to pass in a union to be filled
Date:
Message-ID: <ur777txiq.fsf@agharta.de>
On Tue, 17 Jan 2006 01:41:51 +0000 (UTC), Jeremy Smith <············@decompiler.org> wrote:
> I also prefer not to use a different [...] distribution of Common
> Lisp per week, per application
It's fine for the first few months but it finally wears out, you're
right... :)
--
Lisp is not dead, it just smells funny.
Real email: (replace (subseq ·········@agharta.de" 5) "edi")
Jeremy Smith wrote:
> I also prefer not to use a different Windows distribution of
> Common Lisp per week, per application
Then you should use CFFI, because this should work on every Lisp
implementation. And for SDL, perhaps you should take a look at the
Application Builder project:
http://wiki.alu.org/Application_Builder
Now there is a mailing list and Justin Heyes-Jones has done something with
SDL, too, maybe you want to discuss on the mailing list how to combine your
work. I've setup a SVN repository for the project, which is mirrored on my
webpage daily, please send me an eMail, if you want write access.
--
Frank Buss, ··@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de