jmckaskill / luaffi

Standalone FFI library for calling C functions from lua. Compatible with the luajit FFI interface.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ffi.new() - add variable number of arguments for Initializers

jamesgraves opened this issue · comments

According to the rules for initializers:

http://luajit.org/ext_ffi_semantics.html#init

"Aggregate types (arrays and structs) accept either a single table initializer or a flat list of initializers." So we should be able to initialize a C array with a table:

list = ffi.new("int[3]", {10, 20, 30})

or by giving all the arguments to the ffi.new() call itself:

list = ffi.new("int[3]", 10, 20, 30)

However, the latter does not work, and you get an error:

unable to convert argument 2 from lua<number> to cdata<int[3]>

Thanks for the report.

Note to self: expand set_value et all to take a range or consume to the top of the stack

@justincormack You should be able to undo the extra tables in ffi.new('fd_t', {4}) etc.