lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mar 1, 2017, at 3:10 AM, Soni L. <fakedme@gmail.com> wrote:

> So, Lua has very limited OOP:
> 
> object:method() --> object.method(object)
> 
> But, there are other forms of OOP which are useful:
> 
> object.system.method(object)
> object.trait.method(object)
> 
> These could be added to Lua as a new syntax sugar, the `:.` syntax:
> 
> object:system.method()
> object:trait.method()

Why all the trouble? I mean, you could just use free functions:
object_system_func(a, b, c)

This is faster (no need for nested dynamic table look ups) and there is no need for "self" parameter that is magically more important than the others. Also you don't need to artificially invent new classes just because you want to add a function that does not naturally fit into your existing class hierarchy.

Petri