4 ms·
Lua uses : for a method call and IMHO it is easier to read than with a dot.
by citrin_ru 4y ago
Lua uses : for a method call and IMHO it is easier to read than with a dot.
- rollcat 4y agoI think it's the most underrated "wart" of Lua. It's not strictly speaking a method call operator; it's a shorthand used to provide the LHS object (a table) as the first argument in a function call (where the function is looked up from that table). So if you've implemented some form of inheritance (usually via metatables), you can trivially up/down-cast by using the dot notation and specifying the desired class/prototype for the method, and some instance/object as the first argument. (Speaking of up/down-casting, classes, and instances in Lua is a bit awkward. I have a very quick & dirty "class.lua" file that I copy&paste between projects, I wish something like that was just a part of the stdlib.)
- camgunz 4y agoYeah will +1 this. If you mess it up it's pretty hard to find where you did it. ':' is very close to '.'.