1 The `cdata.ptr()` method returns a pointer to the cdata. The `cdata.deref()` method 2 dereferences a pointer to read the value. 3 4 Pointer and dereference basic usage. 5 6 -- Testcase -- 7 {% 8 import * as ffi from 'ffi'; 9 10 let i = ffi.ctype('int', 42); 11 let p = i.ptr(); 12 13 let addr = p.get(); 14 print("address is valid: ", addr != null && addr > 0, "\n"); 15 print("value: ", p.deref('int'), "\n"); 16 -- End -- 17 18 -- Expect stdout -- 19 address is valid: true 20 value: 42 21 -- End -- 22 23 24 Dereference returns primitive value directly. 25 26 -- Testcase -- 27 {% 28 import * as ffi from 'ffi'; 29 30 let i = ffi.ctype('int', 123); 31 let p = i.ptr(); 32 let v = p.deref('int'); 33 34 print("type of deref: ", type(v), "\n"); 35 print("value: ", v, "\n"); 36 -- End -- 37 38 -- Expect stdout -- 39 type of deref: int 40 value: 123 41 -- End -- 42
This page was automatically generated by LXR 0.3.1. • OpenWrt