lua-users home
lua-l archive

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


On 11/28/07, alex.mania@iinet.net.au <alex.mania@iinet.net.au> wrote:
> It seems correct when I think about it, because I cannot envision a scenario where
> you have:
>
> Table1.__index = Table2; Table2.__index = function()
>
> Yet would prefer Table2 do be passed to the function then Table1, should Table1 be
> the object being indexed.

I disagree.  Pure Lua allows you to create proxy tables that sort of
act like the real thing.  Lua should evolve towards making proxy
tables work even more transparently.  (Tables should respect __len,
for example; or as Rici Lake has suggested, pairs() could respect a
new __pairs metamethod.)

Unless I misunderstand your meaning, your proposal makes proxy tables
work less like real tables, as they would now be unsuitable as a value
for __index.

For example:

-- using http://lua-users.org/wiki/ReadOnlyTables:
ro = readonlytable { greeting = 'Hi!' }
test = setmetatable( {}, { __index = ro } )
-- or, as another example: test = readonlytable(ro)
print(test.greeting)

-- Lua: Hi!
-- Modified Lua: nil

Greg F