On Thu, May 16, 2013 at 10:27 AM, Rob Kendrick <rjek@rjek.com> wrote:
Alternatively, if you're trying to turn Lua into some other language
with heavyweight OOP, perhaps you should be using something other than
Lua.
Yes, with a dynamically-typed language with closures, you don't need all the machinery, and in fact it gets in the way. It _could_ be done (although offhand I don't know an implementation of the concepts of interfaces and abstract classes) but in C++ it's a necessity, whereas in Lua it's a way of getting better runtime errors, at the cost of making everything unnecessarily rigid and strongly coupled.
An interesting idea which is definitely transportable is Go's idea of _interfaces_; if we have an interface containing a single method like 'write', then _any_ type which implements that method satisfies the interface, even if that type didn't 'implement' that type explicitly. It doesn't work in the case of function overloading, but Go and Lua don't have that problem anyway.
I would recommend that the OP reads as much 'idiomatic' Lua code as possible, to see how experienced programmers use Lua. I do use classes, but have never felt the need for multiple inheritance (which has a runtime cost anyway)