When in Lua you write a local
statement, you are declaring that the following identifiers will denote local variables, whether or not those statements actually initializes the variables.
Moreover, local variables in Lua have block scope, i.e. they are visible in the block in which they are defined and in every enclosed block. Blocks are, for example, function bodies, then-end
or else-end
blocks, do-end
blocks, etc.
Keep in mind, also, that variables in Lua don't have type, their value have.
-- declares `a` as a local variable (having no value, i.e. `nil` value)
local a
-- declares `b` as a local variable having 2 as value
local b = 2
-- declares `f` as local var having a function as value
local f = function(x) return x * x end
do
-- `a`, `b` and `f` are visible here, because this is a block enclosed
-- in the block where those vars were declared
local aa = 2
end
-- `aa` is not visible here, because it was declared in an inner block