• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Class:method() or Class.method(self)?

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
3,323
Solutions
26
Reaction score
2,696
Location
Poland
Let's say that I'm making a new method (function) to existing metatable (class), long after the metatable was defined.

Should I register some new method as function Class:getter() ... end or function Class.getter(self) ... end?

What are benefits/downsides of each of them? Is one form better than the other or it's just a matter of preference?
Please don't refer me to documentation, I haven't found anything that would explain it good enough.
 
so summarizing: "." is object instance specific method, meanwhile ":" is class specific method?

. is for reaching table index, : is metatable method definition/call. While both do work, if I understand correctly indexing a metatable through . calls __index twice.

I needed a pretext to refactor libs folder anyway.
 
Back
Top