foreignFunction(lib, symb, rtype, argtypes)
foreignFunction(symb, rtype, argtypes)
Load a function contained in a shared library using the C function dlsym and declare its signature.
|
|
|
The library may be omitted if it is already loaded, e.g., for functions in the C standard library or libraries that Macaulay2 is already linked against. For example, since Macaulay2 uses mpfr for its arbitrary precision real numbers, the above example may be simplified.
|
|
If a function takes multiple arguments, then provide these argument types using a list.
|
|
For variadic functions, set the Variadic option to true.
|
|
|
|
The variadic arguments are processed using foreignObject, which may lead to unexpected behavior. It may be useful to cast them to foreign objects to avoid ambiguity.
|
|
|
|
Note that variadic functions cannot be passed arguments that have a size of fewer than 4 bytes.
|
|
If the foreign function allocates any memory, then register a finalizer for its outputs to deallocate the memory during garbage collection using registerFinalizer.
|
|
|
|
The object foreignFunction is a method function with options.