215 posts
Location
Netherlands
Posted 04 August 2013 - 11:19 AM
I have been talking to my dad and asked him what exactly nil was. He wasn't exactly sure and maybe you guys can answer me on that one. What exactly is the difference between nil and null and when is something nil or null?
7508 posts
Location
Australia
Posted 04 August 2013 - 11:47 AM
a variable is
nil when a value has not been assigned to it…
nil is a keyword, just like
null is a keyword in other languages, used to mean the same thing…
also as makerimages stated in Lua
nil actually resolves to
false, meaning that your if statements could be structured like so
if someVar then
--# do something
end
instead of
if someVar ~= nil then
--# do something
end
8543 posts
Posted 04 August 2013 - 02:51 PM
The only distinctions between nil and null are their respective spellings and which languages they're used in.
997 posts
Location
Wellington, New Zealand
Posted 04 August 2013 - 07:51 PM
In Lua, nonexistent table entries act as if they have the value nil. It's also the default value for global variables (which are really table entries) and local variables.
t = {test=123}
print(tostring(t["test"])) -- prints: 123
print(tostring(t["hello"])) -- prints: nil
print(tostring(asdf)) -- prints: nil
local x
print(tostring(x)) -- prints: nil