lua-users home
lua-l archive

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


On 10/19/2011 6:40 PM, Daurnimator wrote:
On 20 October 2011 11:16, Patrick Donnelly<batrick@batbytes.com>  wrote:
Consider proxy tables. You never actually add anything to the proxy
table. All indexes and sets are redirected. e.g.

t = {}
proxy = {}
setmetatable(proxy, {__index = t, __newindex = function(_,k,v) t[k] = v end})

[I think you can actually just set __newindex to t, but this should
work regardless.]

--
- Patrick Donnelly



In that case, your example still works: not returning anything results
in returning a nil; this will then set a nil in a table: which does
nothing

ALso, you can't set __newindex to a table: that only works with
__index (Though it would be a nice improvemet if there is no
performance loss)



Per Lua 5.2 Reference Manual, section 2.4, __newindex can be set to a table. (Same as Lua 5.1)

-- Mike Nelson