Ok so tried the bawx but nobody seemed to know lua in there so heres my thread instead.
Ok so I know that the counter:get() auto adds the self argument. But how does it know what the self argument is when you call it without giving the self argument a name?Code:counter = { count = 0 } function counter:get() return self.count end function counter:inc() self.count = self.count + 1 end This code is roughly equivalent to the following definition: counter = { count = 0 } function counter.get(self) return self.count end function counter.inc(self) self.count = self.count + 1 end Test this new version with the following code: > print(counter:get()) 0 > counter:inc() > counter:inc() > print(counter:get()) 2
When I call counter.get(counter) it makes sense. However when I call counter:get() without giving it the argument counter it somehow has to know that the invisible self argument is called counter :S