lua-users home
lua-l archive

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

Hi All,

I'm currently implementing a specialised datastore using LuaJIT as part of a larger project.

The datastore uses lua tables to represent fields and nodes, and has a set of functions to merge, delete and retrieve data. As these functions traverse the nested table structure they add information about the current node to stack (another array of arrays). 

Seems to me that it would be more efficient to preallocate all the memory for this stack as cdata, and also to avoid using lua tables which are fairly costly to create and slow to access.*

Each frame in the stack contains the node (lua table) that was updated or traversed, the string key used to access that node in the parent, the template for the node, and the return value after the operation is completed (frames aren't popped immediately, to allow reenterant calls).

The string key and the return value are easy to represent in cdata, but I can't figure out if it's possible to get or store pointers to lua objects. GC isn't a problem because the tables are referenced in other places.

I've not tried embedding LUA in another application yet, so maybe what i'm looking for is somewhere in the C API, if this is the case then i'll gladly go RTFM, just want to know if it's possible?

Many Thanks,

Arran Cudbard-Bell

Betelwiki, Betelwiki, Betelwiki.... !

* Slow is sort of relative here, the system can do about 130K TPS traversing 5 nodes, and inserting 5 fields (yey LuaJIT), but were looking for something in the range of 500K. Almost certainly going to have to move to using CDATA instead of lua tables at some point, but thats more complex, and this is more of a POC currently.