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?

No comments yet!

Lua

!lua@programming.dev

Create post

Lemmy community dedicated to the Lua programming language.

About Lua

Lua is a powerful and lightweight dynamically typed programming language, often embedded into applications to extend their API.

Resources

lua.org - official website
lua.org/pil - book
lua.org/manual - documentation
luarocks.org - package manager

Rules

You may read full set of rules here.
Too long; didn’t read:

  1. Posts must relate to Lua
  2. Use descriptive titles
  3. Provide reproduction code
  4. Information about environment

Community stats

  • 9

    Monthly active users

  • 11

    Posts

  • 0

    Comments