Skip to content

Instantly share code, notes, and snippets.

@Zeta611
Last active May 31, 2020 08:02
Show Gist options
  • Save Zeta611/d5ffaf9e406027f0d5a506d790b06ce3 to your computer and use it in GitHub Desktop.
Save Zeta611/d5ffaf9e406027f0d5a506d790b06ce3 to your computer and use it in GitHub Desktop.
[Lua capture] Shows a full lexical scoping of Lua
function enable_counting()
local count = 0
local old_print = print
print = function(...)
count = count + 1
old_print(...)
end
return function() return count end
end
print("Hello, Lua!")
counter = enable_counting()
print("print called "..counter().." times")
print("print called "..counter().." times")
print("print called "..counter().." times")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment