lua-users home
lua-l archive

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

On Thu, May 31, 2012 at 10:35 AM, Javier Guerra Giraldez
<> wrote:
> On Thu, May 31, 2012 at 12:19 PM, Matthieu Tourne
> <> wrote:
>> Is there a way I could create a Lua table in shared memory, or expose
>> a table like interface so I could store Lua object in my shm segment ?
> it's quite easy to add the hooks to the metatable, try something like
> this, where 'obj' is any 'DICT' object.  usually all objects share the
> same metatable, so you just have to do this once and every DICT object
> should get the new behaviour.
> local mt = getmetatable(obj)
> mt.__index = mt.get
> mt.__newindex = mt.set

I could add this interface to provide syntactic sugar over
shared_dict.get() and shared_dict.set()
But fundamentally a key value store is different than a table, and
can't store nested tables for instance.

Would it be possible to memcpy the entire representation of Lua table
and store it in shared memory ?

But this might have other consequences.
First, the opaque representation of a table might not be portable
between different implementations of Lua.

There is also the case of copying references to objects that will be
not be accessible anymore, because they're outside of the shm segment.

I also looked at lj_tab.c in the LuaJIT code.
I wonder if I implemented all those functions but backed by binary
rbtree in shared memory, I could in theory have the same exact
behavior of a Lua table.

Thanks for ideas,