lua-users home
lua-l archive

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

On 20 October 2011 11:16, Patrick Donnelly <> 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

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)