[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Creating Modules within C
From: |
Ludovic Courtès |
Subject: |
Re: Creating Modules within C |
Date: |
Wed, 22 Nov 2006 18:43:33 +0100 |
User-agent: |
Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) |
Hi,
Volkan YAZICI <address@hidden> writes:
> Hi,
>
> On Nov 17 12:34, Ludovic Courtès wrote:
>> You could write a piece of Scheme to create the relevant module.
>> Namely, you could start with something like this:
>>
>> (let ((m (make-module)))
>> (module-use-interfaces! m
>> (module-public-interface the-root-module)))
>>
>> And then bind that to some variable accessible from C (or pass it to a
>> Scheme procedure written in C that will just store it in a C variable
>> that you can later access).
>
> First, thanks so much for your answer. But I couldn't find any
> documentation about the above make-module, module-use-interfaces! and
> module-use-interfaces functions used. I looked at the source code but,
> because of I'm totally green about module related stuff, couldn't figure
> out anything significant.
A "module" object is (roughly) little more than a hash table (where
symbols of global variables are looked up) and a list of modules
depended on.
`make-module' is the constructor of module objects: it creates, a new,
empty module, with no dependencies and where no bindings are defined
(not even `lambda', `let', etc.) In turn, `module-use-interfaces!'
modifies a module (the first argument) in order to have it depend on a
number of modules (the second and following arguments).
The term "interface" refers to what a module exposes for use by other
modules, i.e., what it exports (more precisely, this is the "public"
interface).
And finally, `the-root-module' is, well, the "root" module of Guile,
i.e., the one that contains all the bindings that are visible "by
default".
> I don't want to be lazy but... Can you please explain a bit more about
> the above usage of modules? For instance, you said, I can bind that
> [thing] to some variable in C. But then how will I use it?
Say you have C variable "my_module" bound to a module created as
explained above. Then, you can evaluate expression in the context of
that module as follows:
SCM result, expr;
expr = scm_list_3 (scm_from_locale_symbol ("+"),
scm_from_int (2), scm_from_int (2));
result = scm_eval (expr, my_module);
This is maybe a bit terse but I hope it helps.
Thanks,
Ludovic.