Hey all,

I’m learning Lua and come from a Java background, and have been diving deep into Lua “classes”.

Realizing that a Lua “class” is just some clever syntactic sugar, and lacks encapsulation, I’ve found that closures can act like a Java class and protect it’s state. An added bonus is my muscle memory won’t struggle with : vs . for function calls, a pitfall I’ve already wasted time debugging.

I’m new to all this though, is there anything I’m missing? Is a Lua “class” with self and : a better choice than using a closure like a class?

  • samus7070
    link
    fedilink
    English
    arrow-up
    3
    ·
    1 year ago

    With any language or platform, don’t try to fight it’s conventions. You’ll just end up frustrated.