On Tue, Feb 28, 2017 at 7:10 PM Soni L. <fakedme@gmail.com
<mailto: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()
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.
--
--
Ryan <vandor2012@gmail.com <mailto:vandor2012@gmail.com>>
Software Developer / System Administrator
https://hashbang.sh