q66 / cffi-lua

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

Support `char [N]` assignment from string #14

Closed vsergeev closed 3 years ago

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

ffi.cdef[[
struct foo {
    char str[4];
};
]]

local f = ffi.new("struct foo")

f.str = "abc" --> expected: no error, get: "invalid C type"
print(ffi.string(f.str)) --> abc

f.str = "abcd1234"
print(ffi.string(f.str)) --> abcd