[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Undefined variables returning nil
- From: Javier Guerra Giraldez <javier@...>
- Date: Wed, 20 Mar 2013 12:18:06 -0500
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
- References:
- Undefined variables returning nil, William Sumner
- Re: Undefined variables returning nil, Petite Abeille
- Re: Undefined variables returning nil, William Sumner
- Re: Undefined variables returning nil, Kaj Eijlers
- Re: Undefined variables returning nil, William Sumner
- Re: Undefined variables returning nil, Petite Abeille
- Re: Undefined variables returning nil, William Sumner
- Re: Undefined variables returning nil, Geoff Leyland
- Re: Undefined variables returning nil, William Sumner
- Re: Undefined variables returning nil, William Ahern
- Re: Undefined variables returning nil, Josh Simmons
- Re: Undefined variables returning nil, Kaj Eijlers
- Re: Undefined variables returning nil, William Sumner
- Re: Undefined variables returning nil, Coda Highland
- Re: Undefined variables returning nil, William Sumner
- Re: Undefined variables returning nil, Enrico Colombini
- Re: Undefined variables returning nil, steve donovan
- Re: Undefined variables returning nil, William Sumner