Functions in Lua are first-class values.
In the first example, the function is defined, in another word, the variable finddir
has a value of type function
. So you can call it.
In the second example, the function has not been defined when you call it, in another word, the varialbe finddir
has a value nil
, thus you can't call it.
It's not that different with other types, e.g:
n = 42
local a = n + 3 --fine
vs
local a = n + 3 --error, n is nil
n = 42