Re: how to send lua table to c/c++ by luajit.ffi ?

  • From: Coda Highland <chighland@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Tue, 26 Nov 2013 19:15:37 -0800

On Tue, Nov 26, 2013 at 7:09 PM, cosnis zhang <cosnis@xxxxxxxxx> wrote:
> thanks, but if i don’t know how much char’s in the struct, and how to do…

If they're all the same data type, LuaJIT does offer variable-length arrays.

http://luajit.org/ext_ffi_api.html

This is likewise untested, but I think it'd be something like:

local vla = ffi.new("char*[?]", #t, unpack(t))
myCFunction(#t, vla)

Remember that there's no way to inspect the length of an array in C so
you'll have to pass the length explicitly to the function.

/s/ Adam

Other related posts: