lua-users home
lua-l archive

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



On 19-Sep-06, at 8:46 AM, David Given wrote:

Andreas Stenius wrote:
[...]
Lock down the access of non-defined values, this will give the user an
appropriate (runtime) error message.

Yes, this might work; it does have the side effect of preventing the
user from using nil in any globals, but I don't think my configuration
language requires this... ta!

Take a look at etc/strict.lua in the Lua distribution for a more
sophisticated implementation: in particular, it avoids the problem
with lookup of undefined globals in C functions (including lua.c)
and provides a mechanism to "declare" legal globals whose value is
nil.

Note that it's not necessary to test rawget(self, key) in an __index
metamethod (of a table) because the semantics of __index are that
__index is only called if rawget(self, key) is nil. It's not clear to me
why the __index metamethod in etc/strict.lua returns rawget(self, key)
in the last line, rather than just returning nil, so perhaps I'm
missing some odd corner case.