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 18:49:32 -0800

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: