lua-users home
lua-l archive

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


The problem with the first solution is that once you set a member to nil you
can't use it anymore.

So I'm going with the second approach.

-----Original Message-----
From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org] On
Behalf Of Petite Abeille
Sent: Tuesday, March 19, 2013 5:42 PM
To: Lua mailing list
Subject: Re: Undefined variables returning nil


On Mar 20, 2013, at 1:07 AM, William Sumner <prestonsumner@me.com> wrote:

> One can't assume all programmers are perfect, especially non-professional
ones exposed to scripting APIs in games. Certainly, none of us are perfect.
Otherwise, we'd have no need for compiler errors.

Perhaps this is merely a simple divide between "Easier to Ask for
Forgiveness than Permission" vs. "Look Before You Leap". Lua is firmly in
the first camp. 

In the meantime, feel free to turn any table into LBYL with:

superdupersafe = setmetatable( {}, { __index = function( self, aKey ) error(
( 'Undefined %q' ):format( aKey ) ) end } )

And, if you really feel strongly about any of this, roll your own version of
Lua. Perhaps it will get some legs. Or not.