2016-04-14 38 views

cevap

3

Yapıya ait alan adlarının listesini almak için dahili ctype bilgilerini okumak üzere ffi.typeinfo kullanan ffi-reflect Lua kitaplığını kullanabilirsiniz.

local ffi = require "ffi" 
local reflect = require "reflect" 

ffi.cdef[[typedef struct test{int x, y;}test;]] 
local cd = ffi.new('test', 1, 2) 

function totab(struct) 
    local t = {} 
    for refct in reflect.typeof(struct):members() do 
    t[refct.name] = struct[refct.name] 
    end 
    return t 
end 

local ret = totab(cd) 
assert(ret.x == 1 and ret.y == 2)