I really like a Lua as a programming language for a variety of reasons. It is probably my favourite language for prototyping and just messing around with. However one of the pain points I hear people talk about often is the minimal standard library that comes with the interpreter. Perhaps to alleviate some of that frustration but mostly just to talk about some libraries that I think are really cool, I wanted to put together a list of my favourite 5 Lua libs. Many of them are very general but some of them are more geared toward game development since that tends to be what I use Lua for.
MiddleClass is an OOP library. It’s straight-forward and gives a lot of the OO features that you would probably want in a library like this including static methods, subclassing, mixins and various helpers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
1 2 3 4
Busted is a unit testing framework. Easily the best one I’ve seen for Lua. It’s well-documented, flexible and very fully-featured, even supporting alternative language packs. It has several assert styles, object introspection, mocks and spies and error trapping, oh my! If you’re used to writing unit tests with any other framework, this will probably not be a big leap for you.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
The collision library with the juvenile name, Hardon Collider is nevertheless great at what it does. I tend to hate physics libraries that try to do too much for you which is why I love this one. You provide callbacks for when objects collide and stop colliding and it handles everything else using a nifty technique called “spatial hashes” (which is to say that it only checks for collisions between objects that are close to each other in the collider space). The callbacks get passed the time delta, the two physics objects and how far they would have to move to resolve the collision. It makes it really easy to offload the collision handling into the game objects themselves thereby compartmentalizing your code really nicely. For example, here’s the entirety of the collision callback for [Gridphreak].
1 2 3 4 5 6 7 8 9 10 11
cron.lua are a set of functions for executing actions at a certain time interval and it is amazing. Put a single reference to
cron.update(dt) in your game loop and then just execute callback functions whenever you want complete with Lua’s super powerful scoping. You can build entire games with this thing; it is really nice.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
Inspect.lua is a really simple tool for debugging the contents of tables. It’s the kind of thing that might even be cool to implement just for the learning but this one is pretty nice. Every project of any decent size is probably going to wish for something like this at some point.
1 2 3 4 5
And there you have it. Three of these libraries are written by one guy, kikito, so if you want to browse more cool Lua, you should head over to his github.