lua-users home
lua-l archive

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


On Thu Nov 29 4:10 , 'Greg Falcon' sent:
>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

Unless I've misinterpreted how readonlytable() works, I am pretty sure modified lua 
would still print "Hi!". The change only modifies this behaviour:

tab = setmetatable({ greeting = "Hi!", goodbye = "Sayoonara" }, {__index = function
() return rawget(tab, "goodbye") end})
ro = readonlytable(tab)
test = setmetatable( { goodbye = "Ciao" }, {__index = ro} )
print(test.greeting)
print(test.unknownkey)

-- Lua: "Hi!", "Sayoonara"
-- Modified Lua: "Hi!", "Ciao"

So it is true that it would change the behaviour of where you use readonlytable() 
on tables that have function __index metamethods, whether or not you could find 
such a construct in reality would be another question altogether.

- Alex D