call_external
- Format:
- call_external(image,entry,vars,value)
- Returns:
- The value returned by the external function.
- Args:
- image: name of the file, which must be a sharable object library (UNIX) or DLL (Windows) which contains the routine to be called.
- entry: entry point of the procedure or function.
- vars: list containing the variables to be passed to the called routine.
- value: list of 1's and 0's corresponding to the variables passed to the routine. 1 means pass by value, 0 (default) means pass by reference.
The call_external proc calls a function in an external sharable object and returns a value. Routines called in this way must adhere to the C (argc, argv) calling convention.
Example:
Assume you wish to call a routine to add some numbers together. The C routine might look something like this:#include float sum_array(int argc, void *argv[]) { float s = 0.0; int i; for(i = 0; i < argc; i++) s += (float)argv[i]; return(s); }The following statements could be used to compile the example and produce a sharable object library on the Linux operating system:gcc -fPIC -c example.c ld -shared -o example.so example.oThe compiled routine can then be called from BYOND using the following code:var/nums[] = list(1.43, 0.44, 5.478, 22) var/vflags[] = list(1, 1, 1, 1) var/sum = call_external("example.so", "_sum_array", nums, vflags)
This could be an incredibly powerful feature - if BYOND doesn't directly support what a game developer wants to do, no problem! Just call an external routine to do it. The inverse, a library of C functions to call a BYOND proc from within a C/C++ program would be just as useful.