[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Web Development with Guile in HB
From: |
Gary Houston |
Subject: |
Re: Web Development with Guile in HB |
Date: |
12 Nov 2000 11:01:35 -0000 |
> From: Alejandro Forero Cuervo <address@hidden>
> Date: Sat, 11 Nov 2000 20:55:50 -0500
> 1. Is there any workaround to having to call a function that never
> returns (such as gh_enter or scm_boot_guile)? I know this makes it
> easier to write the garbage collector but it makes it impossible
> (impossible, not just very hard and complex) to build support of
> Scheme as a module/plugin (at least using HB's definition of
> modules). Or are the only workarounds stupid hacks such as forking
> and dedicating one process entirely to execute Scheme code?
The CVS version of Guile has this in NEWS:
** New function: scm_init_guile ()
In contrast to scm_boot_guile, scm_init_guile will return normally
after initializing Guile. It is not available on all systems, tho.
> 2. How can I make functions such as `display' call my callback
> functions rather than print to stdout? In an application server,
> such as HB, printing to stdout is stupid. I want to capture
> whatever output the Scheme code produces and add it to some
> buffers. Redefining those functions (how?)? Or can I call some
> functions to set my callback function so it gets called rather than
> something that calls write/printf?
String ports could help with this problem:
from Scheme:
guile> (with-output-to-string (lambda () (display "eionwe")))
"eionwe"
from C:
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).
> 3. How can I define procedures (as with gh_new_procedure) in a way
> such that my callback functions get passed a given void pointer I
> specify? This is necessary because HB uses multiple threads to
> attend requests simultaneously so my functions need to know which
> was the HTTP request that caused them to be called. For example,
> in the previous question, my function needs to know what buffer it
> should work with.
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.
> 4. Is Guile reentrant/thread safe? Or should I wrap all calls to
> Guile functions with a mutex/lock? In case it can be compiled both
> ways, how can I find out how it was compiled?
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.
> 5. How can I use multiple environments/contexts/name-spaces? So if HB
> executes some code in some file with a few (define)s, only that
> code can see them. I guess this is not necessary when parsing
> input from just one user, but when we have an application server
> executing code from different files and different users, we need
> separate contexts for each. I read some examples in a tutorial but
> it was extremely outdated. Could someone point me to an example on
> how to do it in the latest version?
Probably tied up with the solution to 4, you want each thread to have
it's own module.