Created
September 28, 2023 07:22
-
-
Save outsinre/dfef8d3687cadaa38105e6e65cf3190b to your computer and use it in GitHub Desktop.
Lua forward declaration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local func -- Forward declaration. `local func = nil` is the same. | |
local function func2() -- Suppose you can't move this function lower. | |
return func() -- reference to name, not to its value | |
end | |
-- error | |
print(func2()) | |
function func() -- defined here | |
return 1 | |
end | |
-- correct | |
print(func2()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment