lua-users home
lua-l archive

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




Am 19.07.2016 um 12:14 schrieb Xavier Wang:
2016-07-19 14:57 GMT+08:00 Oliver Kroth <oliver.kroth@nec-i.de>:
Interesting, but out of curiosity. Wouldn't  debug.setmetatable(nil,{__index
= {}}) be faster and arguably simpler? -- Thomas
I guess not. Lua would then try to look up the key in the empty {} table,
and fail

But it will return a nil, and index a nil still return a nil, seems no problem.


It returns a nil, but needs to return an empty table that can be indexed; nil can't be indexed. The original problem was to have something like tab.a.b.c.d.e not throwing an error, if one of the values
tab.a, tab.a.b, tab.a.b.c, etc is nil.

--
Oliver