The : operator

The : operator is used to call methods on an object. Using the : operator requires that the __index metamethod is defined as the metatable itself. If the __index metamethod is set to the metatable itself, the result is to translate t:test(123) into mt["test"](t,123), where mt is the metatable which has been defined using setmetatable for the table t.

Example

mt={}
mt.__index = mt
mt.test = function(self,value)
    if self.total == null then 
        self.total = 0
    end
    self.total = self.total + value
    return self.total
end

t={}
setmetatable(t,mt)
x = t:test(123)            --> x = 123
y = t:test(1)              --> y = 124
z = t.total                --> z = 124