Re: Strange meta __newindex behavior
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Strange meta __newindex behavior
- From: Alan Hightower <alan@...>
- Date: 2007年3月25日 02:28:49 -0400 (EDT)
On 2007年3月24日, Thomas Harning Jr. wrote:
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 }
Those works because you are actually assigning to root.
both work giving me proper notifications, however,
root.sub1.foo = bar
That is not assigning anything to the root... that is obtaining the
'sub1' table from root, then assigning the 'foo' element to the value
'bar'.
No, the second case is independent of the first. When I perform
root.sub1.foo = bar, sub1 doesn't exist in the root yet. After the line
executes, it does, yet I never get called for the new index add. This
seems broken to me.
One potential fix is to, in the __newindex call, attach a metatable to
each new table value of root... if you know that the assigned tables
will not have any metatable, then all is simple... otherwise you'll
have to be sure to properly chain.
How can I chain if I never get called unless someone explicitly adds a new
index directly (verses never getting called for indirect additions)?
--
-------------
Alan Hightower - alan@alanlee.org