1 The `ffi.cast()` function converts values between types. Numeric casts 2 truncate floating point values to integers. 3 4 -- Testcase -- 5 {% 6 import * as ffi from 'ffi'; 7 8 ffi.cdef('typedef int myint; typedef void *ptr;'); 9 10 let n = ffi.cast('myint', 3.14); 11 print("cast int: ", n.get(), "\n"); 12 13 let p = ffi.cast('ptr', ffi.ctype('int', 42)); 14 print("cast pointer: OK\n"); 15 16 let i = ffi.ctype('myint', 100); 17 let c = ffi.cast('myint', i); 18 print("cast same: ", c.get(), "\n"); 19 -- End -- 20 21 -- Expect stdout -- 22 cast int: 3 23 cast pointer: OK 24 cast same: 100 25 -- End -- 26
This page was automatically generated by LXR 0.3.1. • OpenWrt