Possible to store a reference to a lua table in an ffi struct?

  • From: Kaj Eijlers <bizziboi@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Fri, 21 Mar 2014 22:56:00 -0700

Hi,
I am converting some C++ code to luajit and am trying to leverage some of
the strengths of Lua while still being able to use C style structs.

The code I am converting is, as stated, C++. I can live without the
classes, but am stuck with an std:vector<string> which I could easily
replace with a lua table, if I could at least store a pointer to that table
in the struct.
I know I'll have to pin the table as the gc would be confused, but apart
from that, would it be possible?
I don't need to access it from C code, I just want to be able to store a
reference to the table in the ffi struct so I can use it elsewhere.

I tried casting a table to a void* but it won't do that (fair enough, but
aren't tables immovable?), and searching the mailing list for 'table' is
not the most productive :op

Just occured to me - I could maybe somehow create another C type, and
through it`s metatype implement adding and removing strings - the only
problem would be - where to store the strings/table without having to
duplicate an entire vector class (I know I could ffi.new to stuff and
reference that, but how do I put a reference to a lua object in there?)

Is what I'm trying to do insane?

Any help/insight/ideas appreciated :o)

Kaj

Other related posts: