[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Chicken-users] Dynamic Callbacks without SWIG
From: |
Francisco Rafael Leon |
Subject: |
[Chicken-users] Dynamic Callbacks without SWIG |
Date: |
Fri, 10 Jul 2009 10:20:25 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) |
Hello all,
I spent some time struggling to get callbacks working with SWIG, but
then decided that there must be an easier way than dealing with SWIG
pointers and C_save and C_callback. I came up with this (in pure scheme!):
-----------------
;compile this with csc
(use lolevel)
(define-external (dynfcn (double x)) double
((global-ref (string->symbol "myfunc")) x))
(load "rest-of-program.scm")
------------------
You can then re-define "myfunc" as many times as you wish inside of the
interpreted code "rest-of-program.scm". External C code can call
"dynfcn", and it will be dynamically bound inside chicken on each call.
Amazingly, this explicit dynamic binding with global-ref seems to work
fine.
Sincerely,
F. Rafael Leon
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Chicken-users] Dynamic Callbacks without SWIG,
Francisco Rafael Leon <=