[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LuaJIT: referring to Lua values from C/FFI?
- From: Josh Haberman <jhaberman@...>
- Date: Fri, 8 Apr 2011 21:44:57 +0000 (UTC)
Josh Haberman <jhaberman <at> gmail.com> writes:
> 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.
I forgot to mention one related idea I had: the protobuf data itself
could live in a separate data structure that the userdata only has a pointer
to. In that case the Lua object is just a wrapper, and I can cache these
Lua objects in a weak table indexed by the address of the actual data
object (ie. keyed by lightuserdata). When I want to go from one Lua
object to another, I look up the sub-object in the weak table by address.
This approach has some upsides (the actual data structure can be
accessed from any language) but also has some downsides (more
complicated memory management since the language-independent
data structure has to be refcounted or something, worse cache
locality).
So I'm a bit torn.
Josh