[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Guile-user Digest, Vol 21, Issue 16
From: |
Bruce Korb |
Subject: |
Re: Guile-user Digest, Vol 21, Issue 16 |
Date: |
Fri, 27 Aug 2004 09:25:48 -0700 |
> The usual manner of making a C library available to Guile is to
> manually write a wrapper function, though the tools g-wrap and SWIG,
> which use interface descriptions, are available to generate these
> wrappers. Here is an example:
>
> #include <libguile.h>
>
> SCM_DEFINE (jim_norris_puts, "jim-norris-puts", 1, 0, 0,
> (SCM string),
> "Put @var{string} on FILE* stdout.")
> #define FUNC_NAME s_jim_norris_puts
> {
> SCM_VALIDATE_STRING (SCM_ARG1, string);
> /* warning -- SCM_STRING_CHARS is deprecated. Plus, one day the
> chars won't be null-terminated */
> fputs (SCM_STRING_CHARS (string), stdout);
> /* I don't think you have to do this (IIRC Guile waits for all
> threads to enter the SCM API before GC), but you might someday: */
> scm_remember_upto_here_1 (string);
> return SCM_UNSPECIFIED;
> }
> #undef FUNC_NAME
>
> void
> init_jim_norris (void)
> {
> #ifndef SCM_MAGIC_SNARFER
> #include "jim_norris.x"
> #endif
> }
>
> Then call guile-snarf -o jim_norris.x jim_norris.c, compile to a so,
> add a module that calls
> (load-extension "libjimnorris" "init_jim_norris")
On the other hand, I never have figured out why that is considered
preferable to something like the following. All those weirdo
macro things are very distracting:
/*=gfunc jim_norris_puts
*
* what: Put @var{string} on FILE* stdout.
*
* exparg: string, the string to emit
*
* doc: A longer discussion about the function
=*/
SCM
pfx_scm_jim_norris_puts( SCM string )
{
SCM_VALIDATE_STRING (SCM_ARG1, string);
/* warning -- SCM_STRING_CHARS is deprecated. Plus, one day the
chars won't be null-terminated */
fputs (SCM_STRING_CHARS (string), stdout);
/* I don't think you have to do this (IIRC Guile waits for all
threads to enter the SCM API before GC), but you might someday: */
scm_remember_upto_here_1 (string);
return SCM_UNSPECIFIED;
}
#include "jim_norris.ini"
- Re: Guile-user Digest, Vol 21, Issue 16,
Bruce Korb <=