The class library defines all the methods implementing the Foreign Function Interface. The constructor loads a DLL or shared object, which can then be used to call its functions, passing different sizes of parameters and returning different sizes of return values. The foreign functions are called by using a prototype very similar to the one found in the .h header files used by the C compiler. It is also thanks to this mechanism that one can load a DLL containing compiled supplementary functions constituting a plugin. Once a plugin has been initialized, its functions or methods can be called like native wwlisp functions, without use of the FFI. |
Function Type | subr |
Arguments | an object of class library, a string, a list of simple objects |
Return Value | nil or a float or an integer or an unsignedinteger |
Description | calls the function of which the prototype is given as second argument from the library given as first argument, passing to the called function all the arguments given as third and further; a stack frame is built with the arguments using their description in the prototype and then the foreign function is called; if the arguments prototype do not correspond to the description given in the prototype, an error is thrown; the type descriptions allowed in the prototype are: void, char, short, int, long, float, double, and all the pointers to them like void*, char*, short*, int*, long*, float*, double*; the * sign can be separated of the keyword by one or more spaces, like in void *; the * sign can also be glued to the function name, like in char *strcpy(char *, char *); regardless of the type pointed to, the pointer size will always be 32 or 64 bits depending on the CPU (ILP32 or LP64); the returned types are deposited in a compatible wwlisp type; the keyword unsigned is not implemented |
Example | (call libc "int strlen(char*)" "été" ) => 5 |
Function Type | subr |
Arguments | a string |
Return Value | an object of class library |
Description | returns an object containing a handle to a library, ie DLL or shared object (.so) of which the filename is given as argument; if the shared object is not in the path normally searched by the loader, the filename must also indicate the relative or absolute path to the shared object; never call this function directly, but always through make-instance |
Example | (setq libc(make-instance library "libc.so.6" )) |
Function Type | subr |
Arguments | an object of type library |
Return Value | nil |
Description | destroys the object passed as argument, releasing the link to the library |
Example | (destroy-instance libc) |
Function Type | subr |
Arguments | none |
Return Value | a string, or nil |
Description | static call which returns a string containing the last library error message |
Example | (library-errmsg libc) |
Function Type | subr |
Arguments | an object of type library, a string |
Return Value | an unsignedinteger |
Description | returns the address of the library function given as second argument |
Example | (function-address libc "strcpy" ) => 0x4019ca20 |