Created
July 14, 2013 22:13
-
-
Save weswigham/5996325 to your computer and use it in GitHub Desktop.
Lua scope
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
function SomeFunc() | |
local x = 3 | |
local function InnerFunc() | |
x = 22 | |
end | |
InnerFunc() | |
return x | |
end | |
--Now what does this return? This is more clear (in my opinion): 22. The x of InnerFunc goes up until it finds x in scope or hits the global namespace. In this instance, it finds x locally right above it, as we wanted it to. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment