Skip to content

Instantly share code, notes, and snippets.

@outsinre
Created September 28, 2023 07:22
Show Gist options
  • Save outsinre/dfef8d3687cadaa38105e6e65cf3190b to your computer and use it in GitHub Desktop.
Save outsinre/dfef8d3687cadaa38105e6e65cf3190b to your computer and use it in GitHub Desktop.
Lua forward declaration
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