Suppose you have a table with a function in it:
local t = {}
function t.myfunc(foo)
doSomething(foo)
end
You can call this function with .
easily:
t.myfunc(2) --> arguments: foo = 2
If, in that function, you wanted to change other things in the table, you might add the table as the first argument, so you can refer to it in the function (a common pattern in OOP Lua):
t.thing = 2
function t.myfunc(self, foo)
self.thing = self.thing + foo
end
Now, you would pass in t
as the first argument:
t.myfunc(t, 2) --> arguments: self = t, foo = 2
Calling a function with :
makes this whole idea easier by silently inserting that first table argument for you:
t:myfunc(2) --> arguments: self = t, foo = 2
There’s also matching syntax for declaring functions in a table that let you exclude the first parameter from the function declaration:
function t:myfunc(foo)
self.thing = self.thing + foo --> self is actually the first argument, and foo the second
end
Hope that helps