[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Lua and composition
- From: "Soni L." <fakedme@...>
- Date: Tue, 28 Feb 2017 22:10:24 -0300
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()
I believe Lua would benefit from this. Sure, you can just keep a
reference to the object in object.system/object.trait, but then you
can't dynamically add new arbitrary systems/traits:
object.trait = sometraitimpl
object.trait:method() -- wait, why are you not modifying my `object`?
object.system = somesystem
object.system:method() -- ??? you're supposed to modify `object` D:
object.system.ref = anotherobject -- brokenpatching at its finest
And this is why I think it's a good idea.
This could also support any level of nesting:
a.b.c:d.e.f.g() --> do local c = a.b.c; c.d.e.f.g(c) end -- note how
`a.b.c` is only evaluated once
--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.