Help with callbacks
"smallhairytroll" <[email protected]> Sat, 07 Jun 2003 22:13:25 -0000
| Newsgroups | gmane.lisp.corman |
|---|---|
| Message-ID | <[email protected]> |
I am busy testing all the functions with callbacks in the SDL API
and I am having trouble with a function in the Timer API.
Basically the idea is that you define a callback function, then pass
that function to SDL with an interval value. SDL then calls that
function at those intervals.
Here is the prototype for the function callback:
typedef Uint32 (*SDL_NewTimerCallback)(Uint32 interval, void *param);
(PROGN
(EXPORT
'(SDL_NEWTIMERCALLBACK))
(DEFCTYPE SDL_NEWTIMERCALLBACK (:VOID *)))
And this is the prototype for the AddTimer function:
extern DECLSPEC SDL_TimerID SDL_AddTimer(Uint32 interval,
SDL_NewTimerCallback callback, void *param);
(PROGN
(EXPORT '(SDL_ADDTIMER))
(DEFUN-DLL
SDL_ADDTIMER
((INTERVAL UINT32)
(CALLBACK SDL_NEWTIMERCALLBACK)
(PARAM (:VOID *)))
:RETURN-TYPE
SDL_TIMERID
:LIBRARY-NAME
"SDL.dll"
:ENTRY-NAME
"SDL_AddTimer"
:LINKAGE-TYPE
:C))
Here is how I define the Lisp callback function:
(ct:defun-c-callback my-timer-func-1 ((interval Uint32) (param
(:void *)))
(fformat "Timer Fired, Yup."))
And this is how I call the timer:
(setf f-pointer (ct:create-foreign-ptr))
(setf var-1 (ct:malloc (ct:sizeof :LONG)))
(setf (ct:cpointer-value f-pointer) (ct:cpointer-value var-1))
(setf a-timer-1 (SDL_AddTimer
1000
(ct:get-callback-procinst 'my-timer-func-1) f-pointer))
However Corman crashes after the 1000ms when SDL tries to call the
function. What am I doing wrong ?
-Luke
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get A Free Psychic Reading! Your Online Answer To Life's Important Questions.
http://us.click.yahoo.com/Lj3uPC/Me7FAA/ySSFAA/SyjtlB/TM
---------------------------------------------------------------------~->
To unsubscribe from this group, send an email to:
[email protected]
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/