I need to call it from C (because I want the library to basically load
some of its own bindings), so I defined this in my "scmif" interface
layer (see below)
Do you see any problem with this? (I wasn't too sure what you meant by
"it gets complicated") Will this work with arbitrarily nested layers of
callback?
#>
static void *scmif_tmp_toplevel_fn = NULL;
static void _scmif_run_toplevel(C_word c, C_word self, C_word k)
{
void (*fn)(C_word, C_word, C_word) = scmif_tmp_toplevel_fn;
assert(fn);
fn(2, C_SCHEME_UNDEFINED, k);
}
#<
(define
(scmif-run-that-toplevel uname)
(when debug-scmif?
(mpi-print "Running toplevel for unit '" uname "'..") )
((##core#primitive "_scmif_run_toplevel")) )
#>
int scmif_run_this_toplevel(char *name, void (*fn)(C_word, C_word,
C_word))
{
char *err = NULL;
assert(fn);
scmif_init(0, NULL);
scmif_tmp_toplevel_fn = fn;
// this uses CHICKEN_is_running() & so is valid whether or not you're
// in a callback..
scmif_eval_stringf(&err, "(scmif-run-that-toplevel \"%s\")", name);
scmif_tmp_toplevel_fn = NULL;
if(err) {
fprintf(stderr, "WARNING: scmif_run_this_toplevel: executing toplevel
for unit '%s': %s\n", name, err);
fflush(stderr);
return 0;
}
return 1;
}
<#