External code can be loaded into a running Scheme 48 process
and C object-file bindings can be dereferenced at runtime and
their values called
(although not all versions of Unix support all of this).
The required Scheme functions are in the structure
Dynamic-loadloads the named file into the current process, raising an exception if the file cannot be found or if dynamic loading is not supported by the operating system. The file must have been compiled and linked appropriately. For Linux, the following commands compile
foo.cinto a file
foo.sothat can be loaded dynamically.
% gcc -c -o foo.o foo.c % ld -shared -o foo.so foo.o
(get-external string) -> external
(external? x) -> boolean
(external-name external) -> string
(external-value external) -> byte-vector
Get-externalreturns an external object that contains the value of
name, raising an exception if there is no such value in the current process.
External?is the predicate for externals, and
external-valuereturn the name and value of an external. The value is returned as byte vector of length four (on 32-bit architectures). The value is that which was extant when
get-externalwas called. The following two functions can be used to update the values of externals.
Lookup-externalupdates the value of
externalby looking up its name in the current process, returning
#tif the name is bound and
#fif it is not.
lookup-externalon all extant externals, returning
#fany are unbound.
call-external. See the section on calling C functions from Scheme for more information.
In some versions of Unix retrieving a value from the current process may require a non-trivial amount of computation. We recommend that a dynamically-loaded file contain a single initialization procedure that creates shared bindings for the values exported by the file.
Previous: Dynamic loading | Next: Dynamic loading