lua-users home
lua-l archive

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


On Wed, Mar 20, 2013 at 11:57 AM, William Sumner <prestonsumner@me.com> wrote:
> lack of error-reporting for undefined variable

this is where i think we don't agree:  there's no such thing as an
undefined variable

for local variables, it's obvious.  global variables are just table
fields, and this is also what you've been mentioned: typos in table
fields.  so in the end the only "error" case is accessing a table
field before setting it.

so there comes the second point of disagreement: getting nil is not an
error, it's part of the definition of Lua tables

by design, all table fields have 'nil' as the value, so it's not
"silently returning nil instead of an error".  it's specifically nil
because that's what nil means.

now, if you want something else, strict.lua does exactly that: signal
an error if the first access of a table field is reading instead of
writing.  it's commonly used for global variables, but the same
metatable can be applied to any table.

as for making it the default, or creating a new 'undefined' value....
that has been discussed and rejected.  it's doable, but the result is
not Lua.

--
Javier