* how to access subr from scm module?
@ 2002-11-17 21:19 Viktor Pavlenko
2002-11-19 1:50 ` Viktor Pavlenko
0 siblings, 1 reply; 2+ messages in thread
From: Viktor Pavlenko @ 2002-11-17 21:19 UTC (permalink / raw)
Hi all,
I have the following situation:
1) a SCM procedure (*my-c-proc*) is defined in C and exported with
scm_c_define_gsubr;
2) my program loads a SCM module (my-module.scm) by calling
scm_c_use_module("my-module")
3) this module defines some SCM procedures I want to call from C code
4) these procedures will use *my-c-proc* mentioned in (1)
The problem is that *my-c-proc* is not visible in my-module and
scm_call_N will fail with
ERROR: Unbound variable: *my-c-proc*
This procedure, however, is accessible from C since
scm_c_eval_string("*my-c-proc*") produces
#<primitive-procedure *my-c-proc*>.
I would prefer making a SCM module of my C procedures but they are
defined in the same code that wants to use them, so
(define-module (my-c-procedures))
(load-extension "??" "??")
doesn't seem useful. It would be OK though to load them as global
definitions, and scm_c_define_gsubr is supposed to do so according to
the docs:
"Create a new subr object named NAME, based on the C function
FUNCTION, make it visible to Scheme the value of as a global
variable named NAME"
but that doesn't work for me. So what's the trick to make it work and
make it nice?
Thank you in advance.
Viktor
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: how to access subr from scm module?
2002-11-17 21:19 how to access subr from scm module? Viktor Pavlenko
@ 2002-11-19 1:50 ` Viktor Pavlenko
0 siblings, 0 replies; 2+ messages in thread
From: Viktor Pavlenko @ 2002-11-19 1:50 UTC (permalink / raw)
>>>>> "VP" == Viktor Pavlenko <vvp@rogers.com> writes:
VP> I would prefer making a SCM module of my C procedures [...]
... and this is how to do it (I'm posting this in hope it may save
someone's time).
Regards
Viktor
------------------------------------------------------------------>8
#include <libguile.h>
SCM my_proc()
{
return scm_makfrom0str( "testing" );
}
void
init( void* )
{
SCM proc_scm = scm_c_define_gsubr( "*my-proc*", 0, 0, 0, my_proc );
scm_c_export( "*my-proc*", 0 );
}
void
inner_main( void*, int argc, char **argv )
{
scm_c_define_module( "test-module", init, 0 );
/* using it from C */
scm_c_use_module( "test-module" );
scm_c_lookup( "*my-proc*" ); /* OK */
/* to use it from a scheme module loaded from C code:
(use-modules (test-module))
(*my-proc*)
*/
}
int
main( int argc, char** argv )
{
scm_boot_guile(argc, argv, inner_main, 0);
return 0;
}
------------------------------------------------------------------>8
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-11-19 1:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-11-17 21:19 how to access subr from scm module? Viktor Pavlenko
2002-11-19 1:50 ` Viktor Pavlenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).