ffi
使用方法
组件接口
静态函数
函数原型 | 函数作用 |
---|---|
mixed open(string lib_name, string dylib_suffix = "") | Load a dynamic library int open(string lib_name, string dylib_suffix=) |
bool close(int module) | Close a dynamic library |
int symbol(int module, string func_name) | Get function address by symbol in dynamic library int symbol(int module, string func_name) |
mixed call_ret(PendingMode mode, int type_desc, int func_address, ...) | Call function in dynamic library with max 32 arguments, return type is int|real|void Acceptable parameters: nil, int, double, string, buffer, struct(cstruct) NOTE: this function may cause crash if the arguments is not correct |
mixed call_ret_struct(PendingMode mode, int struct_id, int func_address, string type_name = "", ...) | Call function in dynamic library with max 32 arguments, return type is int|real|void Acceptable parameters: nil, int, double, string, buffer, struct(cstruct) NOTE: this function may cause crash if the arguments is not correct |
int define_struct(string name, string mod, int size, array fields) | Define a C struct with specified memory layout, return struct id |
map get_all_structs(string mod = nil) | Get a defined struct information by name |
map get_struct(string name, string mod) | Get a defined struct information by name |
int get_struct_id(string name, string mod) | Get struct id by name, return 0 if not exist |
map get_ffi_type_info(string name) | Get the intenal ffi type info |
mixed ref_struct(int struct_id, int ptr, string type_name = "") | Create a reference struct |
mixed new_struct(int struct_id, bool clear_memory = false) | Create a new struct, memory will be managered by GC |
mixed new_struct_and_create(int struct_id, ...) | Create a new struct and call the create |
int peek_int16(buffer buf, int offset = 0) | Peek int16 from a buffer |
int peek_int32(buffer buf, int offset = 0) | Peek int32 from a buffer |
int peek_int64(buffer buf, int offset = 0) | Peek int64 from a buffer |
float peek_float(buffer buf, int offset = 0) | Peek float from a buffer |
float peek_double(buffer buf, int offset = 0) | Peek double from a buffer |
int peek_ptr(buffer buf, int offset = 0) | Peek int64 from a buffer |
void put_int16(buffer buf, int val, int offset = 0) | Put int16 into a buffer |
void put_int32(buffer buf, int val, int offset = 0) | Put int32 from a buffer |
void put_int64(buffer buf, int val, int offset = 0) | Put int64 from a buffer |
void put_float(buffer buf, float val, int offset = 0) | Put float from a buffer |
void put_double(buffer buf, float val, int offset = 0) | Put double from a buffer |
void put_ptr(buffer buf, int val, int offset = 0) | Put int64 from a buffer |
int reinterpret_as_char(int val) | Reinterpret a 64 bits integer to other C/C++ type value |
int reinterpret_as_int16(int val) | Reinterpret a 64 bits integer to other C/C++ type value |
int reinterpret_as_int32(int val) | Reinterpret a 64 bits integer to other C/C++ type value |
int reinterpret_as_uint8(int val) | Reinterpret a 64 bits integer to other C/C++ type value |
int reinterpret_as_uint16(int val) | Reinterpret a 64 bits integer to other C/C++ type value |
int reinterpret_as_uint32(int val) | Reinterpret a 64 bits integer to other C/C++ type value |
float reinterpret_as_float(int val) | Reinterpret a 64 bits integer to other C/C++ type value |
float reinterpret_as_double(int val) | Reinterpret a 64 bits integer to other C/C++ type value |
int reinterpret_as_int64(float val) | Reinterpret a double to int64 |
int map_function(function func, int expect_argn = -1, bool allow_terminate = false) | Map a script function to c function |
void unmap_function(int func_address) | Unmap a script function |
int get_lua_alloc() | Return pointer of function for lua memory allocation |
array get_alloc_free() | Return pointer of function for driver memory allocation |
示例Demo