lua-users home
lua-l archive

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

On Mon, Nov 26, 2018 at 6:58 AM Egor Skriptunoff
<> wrote:
> On Mon, Nov 26, 2018 at 1:30 PM Soni "They/Them" L. wrote:
>> >> - Lua has little to no support for composition-based OOP
>> > Can you give an example of what you would want here?
>> The classic Cratera[1] `foo:[component].method()` (note the colon) syntax.
> What OOP languages do support this "composition-based OOP" ?

Lots of them. C++, Java, C#, Python... Javascript doesn't usually do
it that way but its ability to do dynamic function rebinding would
make it POSSIBLE to do it there (I just don't know anyone that

The syntax isn't usually that pretty, though. Python's the only one I
know of off the top of my head that can make it look that clean. In C#
it looks more like foo.GetComponent<Component>().Method().

Lua actually can pull it off with foo[component]:method() if you have
foo's __index metamethod return a binding object, but that comes at
the cost of a fair amount of overhead relative to the syntax patch.

/s/ Adam