23
Note that in the above example code, the path
/usr/scripts/user/
is the absolute path of the
script pool where libm228.so will be uploaded. The absolute path must be specified for Alien to
find the shared library.
To use a function in the driver you first must tell Alien the function prototype of driver. This is
performed with the call
lib.func:types(return_type, arg_types…)
. For each driver function that is
to be called. The types are specified as a string and can be any of the types specified in Table III.
Most correspond directly to C data types.
Table III. Alien Data Types
Alien Data Type
C Data Type
“void”
void
“int”
int
“double”
double
“char”
char
“string”
const char*
“pointer”
void*
“ref int”
int
passed by reference
“ref double”
double
passed by reference
“ref char”
char
passed by reference
“callback”
generic function pointer
“short”
short
“byte”
signed char
“long”
long
“float
float
The following example code illustrates how to define the function prototype of the M228 driver
initialize function whose C prototype is:
int m228_Init(int path, int id_query, int reset, M228_HANDLE *handle);
Note that in the below example, we create a variable of the same name as the C function that is
equal to
lib.func
. This is not required but makes for more readable code as from that point on,
the function can be called with the function name.
m228_Init = libm228.m228_Init
m228_Init:types(“int”, “int”, “int”, ”ref int”)
Function prototypes only need to be defined once and can be defined anywhere in the script as
long as it is before the function is called. With that said, it makes for more readable code if all
prototypes are defined in one section near the top of the code.
Once the prototype is defined the function can be called as follows:
path = 0
id_query = 1
reset = 1
error, handle = m228_Init(path, id_query, reset, 0)