lua-users home
lua-l archive

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


> Consider adding a new value next to "nil": "undefined".
> 
> local t = {}
> print ( t["somestring"])  --- prints "undefined"
> t["somestring"] = nil
> print ( t["somestring"])  --- prints "nil"
> 
> Both undefined and nil evaluates to false when used in an if statement.

You may just rename "undefined"->"nil" and "nil"->"false":

t = {}
print(t["somesting"])    --> prints "nil"
t["somesting"] = false
print(t["somesting"])    --> prints "false"

Both nil and false evaluate to false when used in an if statement.

-- Roberto