guile-user
[Top][All Lists]
Advanced

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

Re: Web Development with Guile in HB


From: Alejandro Forero Cuervo
Subject: Re: Web Development with Guile in HB
Date: Mon, 13 Nov 2000 17:00:16 -0500

First, I would like to thank all the persons that replied to my
previous message.  The information you provided has been very helpful.

There is an initial document on how to embed Scheme code in HB's
latest version at <http://bachue.com/hb/hb.cgi/guile>.

    scm_mkstrport creates a string port (strports.c)
    scm_set_current_output_port can set the current Scheme output port to the
    string port (ports.c)
    scm_strport_to_string retrieves the string port contents (strports.c).

This is what I'm doing:  Create a string, make a string port from that
string, set the output port to that string port and then, after
executing the embedded code, retrieve the string from the port and the
contents of the string.  Finally, I set the current output port back
to what it was.  Here is how it looks:

   oldport = scm_current_output_port();

   scm_set_current_output_port(scm_mkstrport(SCM_INUM0,
      scm_make_string(SCM_MAKINUM(0), SCM_UNDEFINED),
      SCM_OPN | SCM_WRTNG, "hbguile_exec"));

   /* Execute the code */

   scm_set_current_output_port(oldport);

I guess that "hbguile_exec" (the name of the function where I have
this code) is just the name of the caller and is used to report
errors.  Am I wrong?  What am I supposed to pass as the caller?

I am also guessing that SCM_OPN means open and SCM_WRTNG means writing
and those are the right flags I should pass to scm_mkstrport here.
Right?

An another thing I'm guessing is that Guile will take care of
destroing the string and the string port when I set the current output
port back to oldport.  Right?

    Since procedures defined by gh_new_procedure only take Scheme
    values, you couldn't use them directly as callbacks that take a
    void *.  You'd need to install a C callback procedure that
    converts the void * to a Scheme value and then somehow finds the
    right Scheme callback to call.

I made a smob and gh_define the void pointer.  The callback functions
must get the pointer passed explicitely.  In the future they will look
for the smob/pointer themselves.  For example, you do:

    (hb-argument hbargs "string")
    (hb-argument hbargs "other-string")

The only thing that changes is "string" and "other-string".  Since
hbargs never changes, its annoying to have to write it everywhere.  I
will have the procedure associated to "hb-argument" lookit up
automatically every time.

    I'm not sure what the current status is, perhaps Guile can only be
    used from one thread.  This could be a big problem for what you
    are trying to do.

For the moment I'll just use a mutex around the code that calls Guile
to avoid problems with this.  It means dead locks are possible
(because, depending on the user's code, some of my C functions that
are callable from Scheme might call others that might want to call
Scheme again).

    In effect, you just create a new module, and import the bindings
    you want to it.

Okay, I'm trying to do that.  I guess my code will have to:

1. Create a new module and import the bindings into it.
2. Set it as the current module.
3. Execute the code.
4. Reset the current module to what it was initially.

Right?

How can I create a new module?  I can't figure out what the parameter
to scm_make_module should be.  I figured I would ask, rather than try
with some random values. :)

I am also assuming that scm_ensure_user_module imports some nice
bindings into it.  Or how should I initialize the module?

Also, how can I get the current module (to be able to set it again in
step 4)?

I am new to modules and haven't found any documentation on them.
Could you please point me to some documents where I can find more
information about them?

I am assuming `modules' means groups of bindings of names to values
(such as "display" is bound to this procedure, "+" is bound to this
procedure, "define" is bound to this procedure, stuff (define)d is
bound to their values and so on).

Thank you very much. :)

Alejo.
http://bachue.com/alejo

--
The mere formulation of a problem is far more essential than its solution.
      -- Albert Einstein.



reply via email to

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