q66 / cffi-lua

A portable C FFI for Lua 5.1+
MIT License
176 stars 24 forks source link

Support struct array element assignment from table #15

Closed vsergeev closed 3 years ago

vsergeev commented 3 years ago
local ffi = jit and require('ffi') or require('cffi')

ffi.cdef[[
typedef struct point {
    int x;
    int y;
} point_t;
]]

local points = ffi.new("point_t[4]")

points[0] = {1, 2} --> expected: no error, get: cannot convert 'table' to 'struct point'

print(points[0].x, points[0].y) --> 1 2

I don't actually use this one, but happened to stumble across it. I didn't realize the LuaJIT FFI allowed it.