guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to access subr from scm module?


From: Viktor Pavlenko
Subject: Re: how to access subr from scm module?
Date: Mon, 18 Nov 2002 20:50:43 -0500

>>>>> "VP" == Viktor Pavlenko <address@hidden> 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]