[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Chicken-users] problem with callbacks
From: |
Daniel B. Faken |
Subject: |
[Chicken-users] problem with callbacks |
Date: |
Thu, 22 Jan 2004 09:34:44 -0500 (EST) |
Hello all,
My 'foreign-callback-wrapper' doesn't seem to be capturing the local
environment - is this correct? (please pardon me if this is obvious - I'm
a scheme newbie)
An example:
-----------tst.scm-------------
(declare (uses extras))
(let ((foo (make-hash-table)))
#>!
__callback void test_fn(int val)
{
extern void scm_callback2(int);
scm_callback2(val);
}
<#
(print "hello!")
(clear-hash-table! foo)
(define-external (scm_callback (int val)) void
(print "callback-val is " val)
(print "in callback: foo is " foo)
)
(define callback2
(foreign-callback-wrapper void "scm_callback2"
(int) (lambda (x) (print "callback-val is " x)
(print "in callback: foo is " foo))))
(print "foo is " foo)
(test_fn 50)
)
-----------------------------
produces this output:
-----------------------------
gloriot2:~/cr/spu/viewpoint/htcam%csc tst.scm
gloriot2:~/cr/spu/viewpoint/htcam%./tst
hello!
foo is #<hash-table>
callback-val is 50
Error: unprintable non-immediate object encountered
tst.scm: 3 make-hash-table
tst.scm: 13 print
tst.scm: 14 clear-hash-table!
tst.scm: 27 print
tst.scm: 28 test_fn
##sys#gc
tst.scm: 23 print
tst.scm: 24 print
in callback: foo is gloriot2:~/cr/spu/viewpoint/htcam%
-------------------------------
(my actual program is of course more complicated)
This fails for 'test_fn()' calling either scm_callback()
or scm_callback2().
thanks for any help!
Daniel
- [Chicken-users] problem with callbacks,
Daniel B. Faken <=