1 Complex nested structs with path-based access. 2 3 Nested struct initialization. 4 5 -- Testcase -- 6 {% 7 import * as ffi from 'ffi'; 8 9 ffi.cdef('struct point { int x; int y; }; struct rect { struct point min; struct point max; };'); 10 let r = ffi.ctype('struct rect', { 11 min: {x: 1, y: 2}, 12 max: {x: 3, y: 4} 13 }); 14 15 print("min.x: ", r.get('min.x'), " max.y: ", r.get('max.y'), "\n"); 16 -- End -- 17 18 -- Expect stdout -- 19 min.x: 1 max.y: 4 20 -- End -- 21 22 23 Struct with array of structs. 24 25 -- Testcase -- 26 {% 27 import * as ffi from 'ffi'; 28 29 ffi.cdef('struct point { int x; int y; }; struct polyline { struct point pts[3]; int count; };'); 30 let poly = ffi.ctype('struct polyline', { 31 pts: [ 32 {x: 1, y: 2}, 33 {x: 3, y: 4}, 34 {x: 5, y: 6} 35 ], 36 count: 3 37 }); 38 39 let pts = poly.get('pts'); 40 print("pts[0]: ", pts[0].x, " ", pts[0].y, " count: ", poly.get('count'), "\n"); 41 -- End -- 42 43 -- Expect stdout -- 44 pts[0]: 1 2 count: 3 45 -- End -- 46
This page was automatically generated by LXR 0.3.1. • OpenWrt