[gambit-list] glut callbacks
Eduardo Cavazos
wayo.cavazos at gmail.com
Sat Mar 21 21:41:04 EDT 2009
Marc Feeley wrote:
> On 21-Mar-09, at 5:12 PM, Eduardo Cavazos wrote:
>
>> Eduardo Cavazos wrote:
>>
>>> I was trying out the opengl library from the wiki.
>>>
>>> Some of the functions in the glut library are used to specify callbacks.
>>> For example, glutReshapeFunc.
>>>
>>> In the glut libraries of Ypsilon, Larceny, and Chicken, I'm able to pass
>>> a Scheme procedure to the 'glutReshapeFunc' procedure.
>>>
>>> Is this doable with Gambit? From the sound of the manual, it seems like
>>> this is not yet supported.
>>
>> I'm thinking about going with a workaround along these lines.
>>
>> This is how 'glutReshapeFunc' is defined in the library:
>>
>> (define glutReshapeFunc
>> (c-lambda ( (function (int int) void) ) void "glutReshapeFunc"))
>>
>> So maybe define a helper procedure which *can* be passed to
>> 'glutReshapeFunc':
>>
>> (c-define (basic-reshape-func width height)
>> (int int)
>> void
>> "basicReshapeFunc"
>> ""
>> (glut-reshape-func width height))
>>
>> That calls a procedure stored in a variable which may be set
>> interactively at a REPL:
>>
>> (define glut-reshape-func #f)
>>
>> Ed
>
> Indeed, for complete portability, the only Scheme procedures that can be
> passed to a C function are the Scheme procedures defined with c-define.
>
> On some platforms (processor and operating system dependent) that can
> execute dynamically generated machine code (32 bit intel, power-pc,
> sparc), you can pass any procedure including closures. This feature is
> enabled if USE_dynamic_code_gen is defined in lib/os_dyn.h and this is
> the default in recent versions of Gambit. Give it a try... it may work
> to pass a closure on your platform... but don't count on it to be portable!
Thanks for the tip Marc. I didn't know about USE_dynamic_code_gen. I am
aiming for portability so I will stick with 'c-define' for now.
Ed
More information about the Gambit-list
mailing list