**UPDATE** This post has been updated to fix some errors that @davebollinger corrected/pointed out.
Thanks Dave!
@Beluga,
This is essentially how it works:
-- This is a module file as an example -- local m = {} local bob = 1 local bill = 2 -- At this point, and in this scope there are three(3) locals -- m, bob, bill function m.doit1() -- Zero (0) locals end function m.doit2() print( bob ) -- Zero (0) locals -- One upvalue: bob end function m.doit3( arg1, arg2, arg3, arg4 ) -- Four(4) locals: arg1, arg2, arg3, arg4 end function m.doit4( params ) -- One (1) local: params -- This is true, event if doit4() is later called like this: -- ???.doit3( { arg1 = "a", arg2 = "b", arg3 = "c", arg4 = "d" } ) end function m:doit5( params ) -- notice use of colon notation local sue = bill print( bob ) -- Three (3) locals: this, params, sue -- Two (2) upvalues: bill, bob end return m
In the code above, you have these chunks:
- The entire file
- doit1() … doit5()
Yes, chunks can contain sub-chunks.
https://www.lua.org/pil/1.1.html
Tip: Take some time to read the these chapters of the PIL:
It will help you a lot with understanding Lua and writing better code.