lua-users home
lua-l archive

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


Thanks to Dirk Laurie, joao lobato, & HyperHacker,
and also Peter Loveday (your message got lost in formatting tho)
I do not have a lot of Lua experience, but I am progressing :)

I now have a pretty lean/clean implementation overriding the assignment operator using the approach of using an empty primary table to call __index & __newindex and storing all the data in a secondary table.

My project is going to use lua-objects as column-types in a RDBMS. Elements w/in the lua-object-column will be indexable (it makes for a pretty cool/lean/fast document-store/object-database)

This means I can have N tables, each of which has M columns, each of which has O elements that can be [un]indexed at any time. And of course each table has P primary-keys.

Efficiency (memory-usage & cpu-usage) is a must for this project (memory-usage is the priority)
 I was thinking of storing the lua-objects as such: ("pk" is primary key)
_G[asql][tbl][col][pk] = {}; -- empty table (calls __index, __newindex)
_G[shadow][tbl][col][pk] = eval(lua_expr); -- table w/ lua-object
_G[indexed][tbl][col] = { el1 = true; el2 = true; }; -- Indexed element per column

NOTE: [pk] is on the end of [asql,shadow] because it is the largest dimension
NOTE: "indexed" is used to trigger index-set/update/delete via __newindex()

The upside to the nested data structure is the each lua-table here will be as small as possible (the pk ones [when integer] may even be stored as arrays), so memory usage is optimised.

The downside to the nested data structure approach is each lookup requires many (i.e. 8) lookups. [4 for "asql", 4 for "shadow"]

My questions are
1.) "asql" and "shadow" are being used as dirt cheap "namespace"s to reduce the risk of people tampering w/ them inadvertently. Changing them on purpose is fine, but I want them namespace'd somehow, how does one do this in Lua, in a clean/performant way?
2.) is there a smarter trade-off than this nested approach?

thanks,
 jak