lua-users home
lua-l archive

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



Hello all. New to Lua and just joned the list with a question. Forgive me if it is already answered somewhere else. I tried to do due dilligence in looking for the solution first. I'm having a problem that just seems like a Lua bug.

I am using Lua as a config/control language for a new project. I have a part of the Lua object tree I am trying to shadow so that I get notificatin of both assignments and function calls anywhere in the tree (as nearly all of it has direct control implications when changed).

I start by setting up a meta table for a root table like such:

root = {}
root._hidden_vals = {}
root._my_meta = {}
root._my_meta.__index = root._hidden_vals
root._my_meta.__newindex = _proc_lua_assignment
setmetatable (root, root._my_meta)

Then, whenever the C function associated with _proc_lua_assignment gets called, it performs needed notifications in C then assigned the value to the _hidden_vals sub table. If the assignment operand is a LUA_TTABLE, it set's up similar code for the new table. My problem is that:

   root.sub1 = {}; root.sub1.foo = bar
or
   root.sub1 = { foo = bar }

both work giving me proper notifications, however,

   root.sub1.foo = bar

alone performs the same Lua behavior (adds a new member to root with type table called sub1 with itself assigned a table containing foo = bar) yet I never get a __newindex meta call in C for the new assignment to root. It would seem that since both cases are adding a new member to root, where one did not exist before, I sould get a notify call or the Lua instruction should fail.

Confused,

-Alan

--
-------------
Alan Hightower - alan@alanlee.org