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

  • From: cosnis zhang <cosnis@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Wed, 27 Nov 2013 10:58:54 +0800

ok.. 

now, i have a dynamic length lua table… may i convert to FFI structs?

like this

local var = {“a”, “b”, “c"}
local var1 = {“a”, “b”, “c"}
local var2 = {“a”, “b”, “c”}

// how to convert to FFI structs.

ffi.C.call(var)
ffi.C.call(var1)
ffi.C.call(var2)

-- 
cosnis zhang

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

On Tue, Nov 26, 2013 at 6:38 PM, cosnis zhang <cosnis@xxxxxxxxx> wrote:  
> like the subject, i want send a lua table like {“a”,”b”,”c”} to c/c++  
>  
> and how to read that value by c/c++?  
>  
> and how to get that count by c/c++?  

The short answer to your question is "you can't." Lua tables are  
purely Lua constructs and can't be sent to C via the FFI. You can use  
FFI structs to assemble data structures that you can send to C  
functions through the FFI, but if you need more generic table  
manipulation you should simply write the code as Lua code.  

Also note that you shouldn't access the Lua state from within a  
function called by the FFI. This is unsupported and can cause crashes.  

/s/ Adam  

Other related posts: