guile-user
[Top][All Lists]
Advanced

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

Re: Difference when calling guile script from C vs interpreter


From: Jean Rene Dawin
Subject: Re: Difference when calling guile script from C vs interpreter
Date: Wed, 21 Oct 2020 13:32:21 +0200
User-agent: Mutt/1.9.4 (2018-02-28)

Hi,

thanks for your responses.

> It's generally preferable to *extend* Guile with C code, rather than to 
> *embed* it in C code.
> This means you turn your C code into libraries, which are turned into Guile 
> modules, then you write a Guile program
> that uses those modules.  I.e. you call to C code from Guile, not to Guile 
> code from C.

Well, in my case I want my C program to load/compile guile scripts during run 
time.
The guile scripts are intended to be altered and then reloaded/compiled from 
within the running C program.

> If you want to really prefer to embed and not extend, then perhaps you can 
> make your Guile files available
> in the %load-path and use scm_primitive_load_path (see documentation). 

> Once you've compiled the Guile module, it should be enough to set the
> GUILE_LOAD_COMPILED_PATH environment variable before booting Guile in C

Right. When I use

   scm_primitive_load_path(scm_from_locale_string("gp.guile"));

and set the environment variables

GUILE_LOAD_PATH=""
GUILE_LOAD_COMPILED_PATH=""

the code is indeed compiled:

$ ./gp 
;;; note: source file gp.guile
;;;       newer than compiled 
/home/.cache/guile/ccache/2.2-LE-8-3.A/home/gp.guile.go
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling gp.guile
;;; compiled /home/.cache/guile/ccache/2.2-LE-8-3.A/home/gp.guile.go


I'm not sure why the empty environment variables work, because the 
corresponding variables in guile look like this:

%load-path: ( /usr/share/guile/2.2 /usr/share/guile/site/2.2 
/usr/share/guile/site /usr/share/guile)
%load-compiled-path:( /usr/lib/guile/2.2/ccache /usr/lib/guile/2.2/site-ccache)

so my home and .cache directory are not included.

What also works is to give the full path to scm_primitive_load_path and unset 
the environment variables:

   scm_primitive_load_path(scm_from_locale_string("/home/gp.guile"));

$ unset GUILE_LOAD_COMPILED_PATH
$ unset GUILE_LOAD_PATH
$ ./gp 
;;; note: source file /home/gp.guile
;;;       newer than compiled 
/home/.cache/guile/ccache/2.2-LE-8-3.A/home/gp.guile.go
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling /home/gp.guile
;;; compiled /home/.cache/guile/ccache/2.2-LE-8-3.A/home/gp.guile.go

For now I'm fine with these solutions. Thanks again.

Regards,
Jean Rene



reply via email to

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