1. Stupid callback question
- Posted by Paul Martin <twilight at WCC.NET> Apr 05, 1999
- 460 views
Hello all, This is probably a stupid question, but right now I'm grasping for straws. I'm writing a wrapper for GLUT and I think I'm having trouble with the event handler. GLUT uses a similar approach that win32lib does for event handling, first you setup the callbacks, and then you run the main loop. The question is, if I'm not using all of the events, will I have to set the ones I'm not using to NULL. I know that is not the case for win32lib, but I'm calling these C routines directly. Thanks Paul Martin
2. Re: Stupid callback question
- Posted by "Cuny, David" <David.Cuny at DSS.CA.GOV> Apr 05, 1999
- 483 views
Paul Martin wrote: > The question is, if I'm not using all of the [GLUT] events, > will I have to set the ones I'm not using to NULL. Assuming that I'm understanding the question, you have set up something like this: if iMsg = EVENT1 then ... call_proc( HANDLE_EVENT1, {...} ) elsif iMsg = EVENT2 then ... call_proc( HANDLE_EVENT2, {...} ) elsif iMsg = EVENT3 then ... call_proc( HANDLE_EVENT3, {...} ) end if And since your application never uses EVENT3 (for example), how can you make sure that it doesn't get triggered? Remember that, unlike most of the Euphoria functions, a routine id value of zero/NULL is *valid*. I sort of wish that call_proc and routine_id worked differently than they currently do - especially for cases like this. It would be *nice* if 0 meant "do nothing" and -1 meant "error, undefined"... but that's not how it (currently) works.You probably can't initialize your variables to a "do nothing" routine, because each no op procedure will have to have the correct number of arguments associated with it. You might consider initializing all your variables to -1 and redefining call_proc and call_func to something like this: global procedure callProc( integer routineId, sequence args ) if routineId > -1 then call_proc( routineId, args ) end if end procedure global procedure callFunc( integer routineId, sequence args ) if routineId > -1 then return call_func( routineId, args ) else return 0 end if end procedure Of course, if you are ever expecting something other than a number back from callFunc, you are in trouble with callFunc, so I typically bite the bullet and just code it manually: if HANDLE_EVENT1 > -1 then call_proc( HANDLE_EVENT1, args ) end if Hope this helps. -- David Cuny