1 The `ffi.string()` function converts between C strings and ucode strings. It's bidirectional: 2 - `ffi.string(char_ptr)` - converts C char* to ucode string 3 - `ffi.string(ucode_string)` - creates char[] buffer from ucode string 4 5 Char* to ucode string conversion. 6 7 -- Testcase -- 8 {% 9 import * as ffi from 'ffi'; 10 11 let ptr = ffi.ctype('const char *', "hello"); 12 let s = ffi.string(ptr); 13 14 print("type: ", type(s), " value: ", s, "\n"); 15 -- End -- 16 17 -- Expect stdout -- 18 type: string value: hello 19 -- End -- 20 21 22 Creating char[] buffer from ucode string. 23 24 -- Testcase -- 25 {% 26 import * as ffi from 'ffi'; 27 28 let buf = ffi.string("world"); 29 print("type: ", type(buf), "\n"); 30 print("deref: ", buf.deref('char'), "\n"); 31 -- End -- 32 33 -- Expect stdout -- 34 type: resource 35 deref: 119 36 -- End -- 37
This page was automatically generated by LXR 0.3.1. • OpenWrt