The @ni module contains a singe class, @import, which allows for interfacing with native code in a shared object (.so) or dynamically linked library (.dll).

@import Methods

:new(library) #

Construct a native import.

Parameters

Return

:declare(signature) #

Declare a native function.

Parameters

Return

Notes

The signature must be in the format: 'type name(type, type, ...)'

Where the first type is the return type, and subsequent types are the argument types. Possible types and their conversions are:

Up to 9 arguments are supported. When the function is called, each argument is automatically converted to the specified native type, and the native return value is automatically converted back to the corresponding Axiom type.

The name is used to search for the function within the library's exports. To examine all exports of a library, you can do the following:

Example

if os.platform()=='windows' some_library = ni.import('some_library.dll') else some_library = ni.import('some_library.so') narf = some_library.declare('int narf(int,char,char*)') print narf(3,'c','axiom is great!') ## some_library.c ## ## /* windows compile: cl /LD some_library.c linux/mac compile: gcc some_library.c -shared -fPIC -o some_library.so */ #include //on windows, you need to explicitly export each function individually //(on linux/mac, all functions are exported by default) #ifdef _WIN32 #define EXPORT comment(linker, "/EXPORT:"__FUNCTION__"="__FUNCDNAME__) #endif int narf(int i, char c, const char* s){ #pragma EXPORT printf("i = %d, c = %c, s = %s\n",i,c,s); return 99; } ## ## output: i = 3, c = c, s = axiom is great! 99 ##