Lua has no inherent, explicit mechanism for object-oriented programming (OOP). No
class keyword or special
object type, nothing of the sort. But it is possible to support OOP with varying degrees of complexity, demonstrated by Lua users.
Today I want to show you how to write and use mixins using a variety of object-oriented Lua libraries. I will assume you are familiar with the concept of mixins, and composition over inheritance, but I am not going to get into the pros and cons. However, I will implement the same logic in each library to help you compare and contrast them for the purpose of mixins. There is not going to be much commentary for each implementation as I (hopefully) will keep the code simple enough to speak for itself. And from there you can draw your own conclusion about which you prefer.
In Lua you cannot write code like this:
i = 0
i += 1
You get a syntax error. Instead you must write:
i = 0
i = i + 1
Friends have asked me before why this is this case, so today I want to explain the reasoning behind this seemingly odd limitation.
The following is a post I wrote on Reddit:
A couple of friends asked me if I had made any progress in finding a new maintainer for PHP Mode. I am happy to announce that I have. Syohei Yoshida (aka. ’syohex’), author of great packages like git-gutter.el and quickrun.el (which I’ve blogged about before), has graciously taken on a co-maintainer role and in quite proactive fashion. I say “co-maintainer” only because I am still not walking away from PHP Mode. I will continue to review patches and offer my input when I can. But Yoshida has been doing work addressing issue, cleaning up older big reports, and managing pull requests. I trust his judgement to the extent that he can merge pull requests into PHP Mode at his own discretion. So if you submit a patch and find it’s been merged by someone who’s not me—well, that’s why.
So I simply wanted to post this announcement in the event that anyone wonders why ‘syohex’ handling pull requests and responding to bug reports. It’s because he’s the new co-maintainer of PHP Mode. And I’m very, very greatful that he’s taken on this role.
Besides, I couldn’t reject help from a guy who shares my enthusiasm for some classic mid-90’s Japanese rock, heh.
After suffering much inner turmoil, I committed the greatest sin of any Emacs user. I am talking about true heresy. There are many great articles by long-time Vim users who made the switch to Emacs via Evil. But I am approaching Evil from the opposite direction. I have used Vim only sparingly, while I’ve used Emacs for a lot of years. Today I want to talk about why I decided to use Evil and share my initial impressions.
Tonight I want to briefly describe the magic system for L’Astra Vojego, the game I’ve been working on for a couple of years. Despite being a shmup it has a number of mechanics from the role-playing genre, and magic is one of those. However, we—i.e. my teammates—wanted to avoid the typical classification of spells that you see in so many games. I must admit that I was personally inspired by Dark Souls and how it divides spells into Sorceries, Miracles, Pyromancies, and Hexes, as opposed to something like Fire, Earth, Water, and whatever else Captain Planet and the Planeteers used.
A number of my friends are board-game enthusiasts, and as such, they’ve introduce me to a number of great games. My personal favorite are those which I can jump into with minimal explanation. As for the rest…. If you create a board game and the instructions contain five or more occurances of the following words, stop immediately and go back to the drawing board:
Simplify, simplify, simplify. Personally, if someone can’t explain a game to me and start the session in less than ten minutes, then I can find something more fun to do with my time. I realize this is hypocritical coming from a Dungeons and Dragons fanatic, but I do my best to introduce new players to the game as quickly as possible—admittedly being hypocritical about my own guidelines sometimes.
At any rate, I want simplicity out of a board game. Not a mandatory fifteen to thirty minute lesson where the game feels more like a high-school quiz than a way to enjoy time with my friends.