导出的变量
变量定义
int my_int = 42;
const char *my_string = NULL;const my_int = lib.symbol('my_int', 'int');
const my_string = lib.symbol('my_string', 'const char *');解码为 JS 值
编码到C内存
Last updated
int my_int = 42;
const char *my_string = NULL;const my_int = lib.symbol('my_int', 'int');
const my_string = lib.symbol('my_string', 'const char *');Last updated
int my_int = 42;
const char *my_string = "foobar";const my_int = lib.symbol('my_int', 'int');
const my_string = lib.symbol('my_string', 'const char *');
console.log(koffi.decode(my_int, 'int')) // Prints 42
console.log(koffi.decode(my_string, 'const char *')) // Prints "foobar"// Only decode 3 bytes from the C string my_string
console.log(koffi.decode(my_string, 'const char *', 3)) // Prints "foo"int my_int = 42;
const char *my_string = NULL;const my_int = lib.symbol('my_int', 'int');
const my_string = lib.symbol('my_string', 'const char *');
console.log(koffi.decode(my_int, 'int')) // Prints 42
console.log(koffi.decode(my_string, 'const char *')) // Prints null
koffi.encode(my_int, 'int', -1);
koffi.encode(my_string, 'const char *', 'Hello World!');
console.log(koffi.decode(my_int, 'int')) // Prints -1
console.log(koffi.decode(my_string, 'const char *')) // Prints "Hello World!"