OOP: is there an alternative way of calling colon functions?

really specific question, are you even able to call colon functions if you index them using square brackets? like this:
image

(the module)
image

when i do this, for whatever reason self is nil. My guess is that this is the same thing as doing s.lol() but if thats the case how would i call it without specifically doing s:lol()?

Yeah you just have to manually pass in self

Like:

s['lol'](s)

You can then add additional arguments after s

This is really all : does in lua, it either causes the function to expect a self argument at the front, or it sends a self argument at the front

3 Likes

Note that these two methods are the same. The colon syntax is what we call “syntactic sugar” which means it’s optional.

local myTable = {}

function myTable.doThing(self, value)
     print(value)
end
function myTable:doThing(value)
     print(value)
end

Basically, colon just adds an invisible self variable as the first variable. :slight_smile:

1 Like