|
| From: | Felix Winkelmann |
| Subject: | Re: [Chicken-users] problem with callbacks |
| Date: | Fri, 23 Jan 2004 08:18:44 +0100 |
| User-agent: | Opera7.21/Win32 M2 build 3218 |
Hello all, My 'foreign-callback-wrapper' doesn't seem to be capturing the local environment - is this correct?
That is correct. Both `foreign-callback-wrapper' and `define-external'
(which expands into the former) do not capture the lexical environment.
The problem is that C invokes the callback directly via it's function
address, to pass the lexical environment and extra argument would have
to be passed. A workaround is to call your target procedure indirectly:
(define bar #f)
(let ([foo 99])
(set! bar (lambda () (print foo))) )
(define-external (cb) void
(bar) )
#>!
__callback void ccb() { extern void cb(); cb(); }
<#
(ccb)
cheers,
felix
| [Prev in Thread] | Current Thread | [Next in Thread] |