For "sub" function, is this notation local?

Hi Lua veterans,
I’m just curious, is the following “sub function” local in Lua scope? The function “TEST” itself isn’t declared as local, but it’s added as an entry (or sub-class?) of the table “sampleFunction”, which is defined as local.

local sampleFunction = {}  
  
function sampleFunction:TEST()  
 --function lines  
end  

So, by this notation, does the function “TEST” remain local, or does it remain global because it’s not *itself* declared as local? I’ve seen this format used in various codeshare modules, and I’m curious how the scoping on this works.

Thanks!
Brent Sorrentino
Ignis Design [import]uid: 9747 topic_id: 23128 reply_id: 323128[/import]

Yeah, think of your function (“sampleFunction”) as a table. “TEST” is local because it is a nested component of that table/function. (As I understand it is addressable simply because your function is like a chunk of memory, holding the code inside, which is good if you need to call something again but bad if you load it up with different functions but only need one.) [import]uid: 41884 topic_id: 23128 reply_id: 92469[/import]

The way to understand this is to realize that the following syntax:

function sampleFunction:TEST( ... )  
 --function lines  
end  

is just convenient shorthand for the following equivalent notation:

sampleFunction.TEST = function( self, ... )  
 --function lines  
end  

That version makes it much easier to understand that the function being assigned is just an anonymous function that can only be accessed from the property to which it is bound, in this case, sampleFunction.TEST. [import]uid: 71767 topic_id: 23128 reply_id: 92486[/import]

Thank you both! When it comes to Lua scopes, even an intermediate programmer like myself can’t always be certain, but this clears it up for me in this notation. [import]uid: 9747 topic_id: 23128 reply_id: 92492[/import]