Programming in Lua - 6.2
Programming in Lua - 6.2
Programming in Lua
Part I. The Language
Chapter 6. More about Functions
Lib = {}
Lib = {
Lib = {}
return x + y
end
return x - y
end
...
end
...
...
end
...
end
if n == 0 then return 1
end
end
local fact
if n == 0 then return 1
end
end
Now the fact inside the function refers to the local variable.
Its value when
the function is defined does not matter;
by the time the function executes,
fact already has the right value.
That is the way Lua expands its syntactic
sugar for local functions,
so you can use it for recursive functions without
worrying:
if n == 0 then return 1
end
end
function g ()
end
function f ()
end