Re: Re: Help with callbacks

"Chris Double" <[email protected]> Wed, 11 Jun 2003 13:39:00 +1200
Newsgroups gmane.lisp.corman
Message-ID <[email protected]>
How does the timer callback work? Is it called back on a seperate thread?
Does it add a timer message to the windows message queue? What does SDL
do to actually call the callback in a timely manner?

Chris.

On Wed, 11 Jun 2003 01:16:28 -0000, "smallhairytroll"
<[email protected]> said:
> I have been adding fprintf statements to the SDL.dll, printing out 
> the values being passed to and from the Lisp callback function.
> 
> Everything checks out: SDL receives and stores the correct address 
> from the callback function. The correct values are being passed back 
> to the callback when it is called (using the correct types, I 
> think), but still Lisp crashes.
> 
> So my question is: Has anyone used a callback in Lisp that is passed 
> two parameters ? Passing a single parameter to a callback works. 
> Passing two parameters doesn't seem to work.
> 
> For the event filter callback that takes a single parameter and 
> therefore WORKS: here is the SDL specific code:
> 
> typedef int (*SDL_EventFilter)(const SDL_Event *event);
> (PROGN 
>   (EXPORT '(SDL_EVENTFILTER)) 
>   (C-TYPES:DEFCTYPE SDL_EVENTFILTER (:VOID *)))
> 
> extern DECLSPEC void SDL_SetEventFilter(SDL_EventFilter filter);
> (PROGN
>   (EXPORT '(SDL_SETEVENTFILTER))
>   (C-TYPES:DEFUN-DLL
>     SDL_SETEVENTFILTER
>       ((FILTER SDL_EVENTFILTER))
>         :RETURN-TYPE
>         :VOID
>         :LIBRARY-NAME
>         "SDL.dll"
>         :ENTRY-NAME
>         "SDL_SetEventFilter"
>         :LINKAGE-TYPE
>         :C)
> 
> // Setting up the callback
> SDL_EventFilter SDL_EventOK = NULL;
> 
> void SDL_SetEventFilter (SDL_EventFilter filter)
> {
>   SDL_EventOK = filter;
> }
> 
> // Fireing the callback
> (*SDL_EventOK)(&event)
> 
> The Lisp code looks like this:
> 
> (ct:defun-c-callback FilterEvents ((event (:void *)))
>   (if (eql SDL_MOUSEMOTION (ct:cref SDL_Event event type))
>     (progn
>       (fformat "Yup, mouse moved")
>        0)
>      1))
> 
> (SDL_SetEventFilter (ct:get-callback-procinst 'FilterEvents))
> 
> 
> Now, for the callback that takes two parameters and DOES NOT work:
> 
> typedef Uint32 (*SDL_NewTimerCallback)(Uint32 interval, void *param);
> (PROGN 
>   (EXPORT '(SDL_NEWTIMERCALLBACK)) 
>   (C-TYPES:DEFCTYPE SDL_NEWTIMERCALLBACK (:VOID *)))
> 
> extern DECLSPEC SDL_TimerID SDL_AddTimer(Uint32 interval, 
> SDL_NewTimerCallback callback, void *param);
> (PROGN
>     (EXPORT '(SDL_ADDTIMER))
>     (C-TYPES: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)
> 
> 
> 
> struct _SDL_TimerID {
>   Uint32 interval;
>   SDL_NewTimerCallback cb;
>   void *param;
>   Uint32 last_alarm;
>   struct _SDL_TimerID *next;
> };
> 
> // Setting up the callback
> SDL_TimerID SDL_AddTimer(Uint32 interval, SDL_NewTimerCallback 
> callback, void *param)
> {
>   t = (SDL_TimerID) malloc(sizeof(struct _SDL_TimerID));
>   t->interval = ROUND_RESOLUTION(interval);
>   t->cb = callback;
>   t->param = param;
> }
> 
> // Fireing the callback
> ms = t->cb(t->interval, t->param);
> 
> And the Lisp code:
> 
> (ct:defun-c-callback my-timer-func-1 ((interval Uint32) (param 
> (:void *)))
>     (fformat "Timer Fired, Yup.")
>     (values interval))
> 
> (setf var-1 (ct:malloc (ct:sizeof :LONG)))
> (setf (ct:cref (:long *) var-1 0) 1001)
> 
> (setf a-timer-1 (SDL_AddTimer 
>         500 
>         (ct:get-callback-procinst 'my-timer-func-1) var-1))
> 
> I just don't know.
> 
> -Luke
> 
> 
> 
> 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/ 
> 
> 
> 
-- 
  Chris Double
  [email protected]

------------------------ 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/