From: "Marco Maggi" <marco.maggi-ipsu@poste.it>
To: "guile-user" <guile-user@gnu.org>
Subject: Re: modules and C
Date: Fri, 23 Mar 2007 08:01:48 +0100 [thread overview]
Message-ID: <JFCGV0$553ACC277414E0D29BD4A43324E9576E@poste.it> (raw)
"David Fang" wrote:
> What do I need to do to export my scm_c_define_gsubr'd
> functions to the module?
YMMV. This is what I do:
1. write a C module with its own initialisation function,
let's say that the module's file is "module.c" :
/* C module */
#include <libguile.h>
/* module functions here */
void
my_module_init (void)
{
}
/* end of module */
put the init function in an internal header file:
void my_module_init (void);
2. wrap all the Scheme interface function declarations
into SCM_DEFINE: for a function with a prototype:
extern SCM my_scheme_func (SCM arg1, SCM arg2);
declared in a header file, I write in the body of the
module:
#undef SFN
#define SFN "my-scheme-func"
SCM_DEFINE(my_scheme_func, SFN,
2, 0, 0, (SCM arg1, SCM arg2), "")
{
SCM s_result;
/* do something with 'arg1' and 'arg2' */
return s_result;
}
the symbol SFN is defined to be the name of the
Scheme procedure: that way the name is available
in the function's body for calls to 'scm_error()',
for example:
/* to throw a 'wrong-type-arg' error */
if (error_condition)
scm_error(scm_arg_type_key, SFN,
"error message",
SCM_BOOL_F, SCM_BOOL_F);
3. in the body of the module initialisation function
put an include for a ".x" file:
void
my_module_init (void)
{
/* other init stuff */
#ifndef SCM_MAGIC_SNARFER
# include "module.x"
#endif
}
4. before compiling: preprocess the "module.c" file
with the Guile snarfer program; I use a rule in
the Makefile, something like this
.SECONDARY: %.x
GUILE_SNARF = guile-snarf
%.x : %.c
$(GUILE_SNARF) $(@) $(<) $(INCLUDES)
%.o : %.c $.x
the ".x" file holds the function invocations
required to define the functions from "module.c"
something like:
scm_c_define_gsubr(s_my_scheme_func, 2, 0, 0,
(SCM (*)()) my_scheme_func); ;
when the snarfer processes the file the:
#include "module.x"
is excluded, but it is included when the compiler
does its job;
now you can use 'scm_c_call_with_current_module()'
and invoke the initialisation function.
--
Marco Maggi
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
next reply other threads:[~2007-03-23 7:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-23 7:01 Marco Maggi [this message]
-- strict thread matches above, loose matches on Subject: below --
2007-03-22 0:17 modules and C dsmich
2007-03-21 22:57 David Fang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='JFCGV0$553ACC277414E0D29BD4A43324E9576E@poste.it' \
--to=marco.maggi-ipsu@poste.it \
--cc=guile-user@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).