lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I know that base Lua does not provide a C representation for "pointer
to Lua value":
  http://article.gmane.org/gmane.comp.lang.lua.general/56515

I was wondering if the same is true for LuaJIT and for the FFI.  I suspect
that it is since it simplifies GC, but I just wanted to ask in case anyone
has interesting thoughts on the matter.

I'm trying to decide how to model a protocol buffer as a Lua object.
Protocol Buffers contain both primitive values (integers, bools, etc.
which I can pack into a userdata more efficiently than Lua can pack
lua_Number) and references to submessages, which would be other
Lua objects.

If I represent the pb as a userdata, I can get my efficient packing of
primitives but can't refer to other Lua values.  If I represent the pb
by using the array part of a table I can refer to other Lua values but
my packing of primitive values is much less efficient.

One idea I had was to have a userdata but use its metatable to store
the references to other Lua values.  That requires a metatable per
instance which is a little extra overhead and it means that the
luaL_checkudata() scheme won't work for type checking, but overall
it's the best idea I have so far.

Josh