In short, a closure is a function with it's environment. See this piece of code:
Code: Select all
do
local x = 0
function f () return x end
function g (a) if a ~= nil then x = a end; return x end
end
-- at this point x is no longer valid
print(f() ) -- returns 0
print(g(5) ) -- returns 5
print(f() ) -- returns 5
x = 0
print(f() ) -- returns 5
print(x) -- returns 0
Anime Studio Lua Scripting: Closure - 3
A closure somewhat resembles an object (as in object oriented programming), though they are two completely different concepts. You tell a closure what it should do (functional programming), and you tell an object how it should do it (imperative programming).
What is the practical use for Anime Studio and Lua scripting? I wish I knew, because I got stuck at chapter 6.1 of Programming in Lua.