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

  • From: cosnis zhang <cosnis@xxxxxxxxx>
  • To: Coda Highland <chighland@xxxxxxxxx>, luajit@xxxxxxxxxxxxx
  • Date: Wed, 27 Nov 2013 11:17:14 +0800

ok, i try it later.

thanks very much~



-- 
cosnis zhang

On 2013年11月27日 at 上午11:16:06, Coda Highland (chighland@xxxxxxxxx) wrote:

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: