I found something in the wiki that may help. I heard of this before and went to the wiki. I found this:
tab = {}
function tab:method( args )
print( "I'm a method from " .. tostring(self) .. " with args " .. tostring( args ) )
end
Now if I call this function like this:
tab:method("Hello there!")
It'll print this:
I'm a method from table: 0x16082c60 with args Hello there!
If you click the link above you can find out more about functions.
I should also add in that this will not attach to any object. You must use _G. But you could make a table in there to make a method like this:
_G.tab = {}
function _G.tab:method(ARGUMENTS_GO_HERE)
end
and then call it like this:
_G.tab:method(ARGUMENTS_GO_HERE)
Good luck on your future Scripting Adventures! ~lightpower26
2 comments
You should look into module scripts. Additionally, you can define a parameter using : with any function, it's not for built-in functions alone.
I think I've seen this done before, but a long time ago. I would not be able to look it up easily.