oh ... so there really is no way to call funcName before it really defines the function? those. do you still need to make sure that defineIt is called before the first call to the funcName function?
I wanted to clarify this point, and I felt that the answer would be a better way than commenting.
Lua is a much simpler language than C or C ++. It is built on some simple foundations, with some syntactic sugar, to make parts easier to digest.
Lua has no concept of a function definition. Functions are first-class facilities. They are values โโin Lua, just like the number 28 or the string literal "foo" are values. A โfunction definitionโ simply sets a value (namely, a function) to a variable. Variables can contain any value, including the value of a function.
All "function calls" take a value from a variable and try to call it. If this value is a function, the function is called with the specified parameters. If this value is not a function (or a / userdata table with the __call __call ), then you get a runtime error.
You can no longer call a function that was not set in a variable, but you can do this:
local number = nil local addition = number + 5 number = 20
And we expect that the addition will contain 25. This will not happen. And therefore, for the same reason, you cannot do this:
local func = nil func(50) func = function() ... end
As Paul pointed out, you can call a function from another function that you define. But you cannot execute the function that calls it until you populate this variable with what it should contain.
source share