luaconditional-statementslua-4.0

Lua 4.0 undeclared variables and conditional statements


This bit of code is confusing me.

print(gogo)
if (gogo == true) then
    print("yes")
elseif (gogo == false) then
    print("no")
end

Why is gogo evaluating as true? Shouldn't it spawn an error instead?


Solution

  • It doesn't evaluate to true and it can't because there is no boolean type in Lua 4.0.

    print(true) -- prints "nil"
    

    Undefined global variables are nil by default, so indeed gogo == true. They are both nil.