Loader guide
Loader is a class that allows one to load arbitrary C functions (with a few limitations, see below) and call them from within Kite. It's designed as a stopgap for those who want to access functionality not specified in the current Kite specification.
WARNING: loader only works properly on 32-bit x86 processors. RISC and x86-64 use call-in-register parameter passing, which is at odds with the way the loader's supposed to work.
Loader methods
- new(libName, retType, argTypes, funcName): Loads function funcName in the library specified by libName. retType is a single character specifying the function's return type, while argTypes is a sequence of characters that specify the types of each individual argument. Valid characters for both of the latter arguments are:
- v: void
- s: string (char*)
- c: char
- h: short
- i: int
- l: long
- f: float
- d: double
- o: long double
- call(...): calls function loaded with the new call with the arguments passed in and returns the type of object specified in retType above. For numeric types (both integer and floating point), a numeric object will be returned. char* will return a string object.
Loader limitations
The loader class only supports primitive C types. Pointers other than char* are not supported. Also, as mentioned above, the code only works properly on 32-bit x86 machines, and a maximum of three arguments can be used (this can be increased by editing KiteExternalFunction?.cpp).
Loader example
This converts a string into a number using atoi() instead of Kite's implied conversions:
var func = loader|new("/lib/libc.so.6", "i", "s", "atoi");
func|call("42")|print;
Result:
42
