|
object.component.method(object) => object:component.method()^ I also tried this syntax (and was sad it didn't work), but it's not so bad. That strategy makes for cross-cutting communication between components, which is not the greatest thing. It also assumes that call your parents, but not your grandparents! Here's my alternative, a "parent" variable:Within calls, replace:object.component.method(object) => object.component:method()And within component methods:self => self.parentself.<<name of this component>> => selfThen, just add a parent member to constructors.This also makes it easier to do the better thing; preferring self.x over self.parent.x, which avoids conflict and does some "light" encapsulation. If you do cross-cutting communication within the parent, rather than between components, that's also better, and you might not even need a parent variable at all.Let me know if that's helpful.On Mon, Nov 26, 2018 at 6:01 PM Russell Haley <russ.haley@gmail.com> wrote:On Mon, Nov 26, 2018 at 2:30 AM Soni "They/Them" L. <fakedme@gmail.com> wrote:
On 2018-11-26 7:22 a.m., Pierre Chapuis wrote:
> On Mon, Nov 26, 2018, at 01:15, Soni They/Them L. wrote:
>
>> - Lua has little to no support for composition-based OOP, whereas it has
>> many features to support inheritance (__index/__newindex) and other
>> forms of OOP (self:methods()). This isn't a big deal, tho, as it can be
>> easily solved with a rather small patch.
> Can you give an example of what you would want here?
>
> Because for me, "composition-based OOP" does not need much
> language support. For what it's worth I almost never use inheritance
> in Lua (or any other language, really).
>
The classic Cratera[1] `foo:[component].method()` (note the colon) syntax.
[1] https://bitbucket.org/TeamSoni/cratera
I looked at cratera once but didn't grasp the benefits because I don't write games. Months later I was reading Roblox game code and the use case for cratera became crystal clear. Likewise, Garry's Mod has very deep component nesting and a library like cratera would simplify development.[1][1] I still don't write games so I may be off mark.Russ