lua-users home
lua-l archive

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




On 01/03/17 12:52 AM, Charles Heywood wrote:
Just gonna mention, FusionScript has a syntax similar to this. When using classes, you can specify a "class" to pull a "method" from, so that obj:class_method<Class>() calls Class.class_method(obj); you can do something similar with obj.class_method<obj.class>() if you don't have a "class table" you can pull the method from.

What if I want obj:class_method<Class>() to be more *dynamic* and call obj.Class.class_method(obj), for use with composition (traits and systems/ECS)?

I guess you mentioned obj.class_method<obj.class>(), but if I'm gonna use that, might aswell just use obj.class.class_method(obj) >.<


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

--
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.