I’ve been learning a lot about object oriented programming over the last year, and there are a bunch of great design patterns and principles that can be used in OOP languages.
But how would I translate that knowledge into something like Defold, where certain things are missing, like interfaces, structs, and static typing? And how would I design a UML diagram for a Defold project?
I know hxdefold exists, and I could use OOP practices there, but I’d like to know how you do this with Lua.
While you can of course adopt OOP to Lua I will tell you something else : I’m using OOP in my daily job and it suits it very, very well and I like how can I organize everything there, though in Defold and generally in gamedev it is more convenient to use ECS. You can of course stretch Lua to fit OOP approach, but if I were in your shoes, I will try to learn a new approach (which is really comfortable, even for devs used to OOP)
In fact Lua tables are like objects: https://www.lua.org/pil/16.html
Think of Lua tables as objects in which you can put everything, including behaviour (functions). They still won’t provide you a direct way to inheritance (but it’s possible), however when you tinker here a little bit you will probably see it’s conveninent - as you can “extend” tables however you like
I don’t think OOP is a panacea. It can result in obfuscated code (OOOP).
I suggest considering a more functional and data driven approach, which I prefer.
Lua modules (and closures) are great for this, I don’t see the attraction of faking OOP.
Basically be in control of your data and avoid side effects.
I’ve been watching an edx CS50 course focused on game development. The course uses the LÖVE game engine and I was hoping to adapt some principles and techniques to Defold because of the common use of Lua. The course starts with Pong and the instructor makes use of a Lua script class. The script can be found in a LÖVE utility named hump ( Helper Utilities for Massive Progression).
OOP in Lua might be treated as just a pattern, like any other generic enough functionality is a pattern in other languages (like e.g. implementing own iterator). Lua is better suited for functional programming, but devs used to object oriented programming will be searching for this “way of thinking” in Lua anyway