lua-users home
lua-l archive

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


hi Peter

On Sun, May 09, 2010 at 06:29:18PM +0100, Peter Cawley wrote:
> How exactly to empty tables show up? You'd get nil when accessing a
> non-existent value:
> Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
...
> Note that debug.setmetatable(nil, {__index = {}}) is equivalent to
> debug.setmetatable(nil, {__index = function() return nil end}) rather
> than debug.setmetatable(nil, {__index = function() return {} end})

of course you are right, sorry, I mixed it up on a quick glance.

Yet the question remains:
if accessing a nonexistend index is not an error,
what is the rationale of making access to any index in nil an error?

>From a type coercion point of view,
I can see a simple and clear rule that makes perfect sense:
Lua does implicit string/number conversion and that's it.

But then, indexing existing tables somehow kind of
converts nonexistent values to nil.
If nil is a good notion of "nope, sorry" for [index],
maybe it should likewise be acceptable at other places?


regards
Klaus