Lua Series
Lua is a small scripting language designed to be embedded into C/C++ code. It is commonly used for this purpose in games and, most famously, in Roblox. Engineering teams often turn to Lua when they need to include some type of scripting and/or configuration in their systems. It provides a robust scripting engine purposely designed for embedding and is covered by a relatively non-restrictive license.
I first came across Lua when configuring routing for Nginx. It was useful, easy to learn, and, most importantly, robust. I followed that up with some scripting in Redis which was equally as useful. I did not think much more about it until I started using Neovim for which Lua is the language for creating plugins. This was when I started to have a lot of fun with Lua.
My intent with this series
This is not the place to learn Lua (check out the resources section for some ideas with that). My intention is to cover the basics sufficiently that it provides a quick refresher when I come back to Lua after a break. From time to time I add interesting tidbits that I stumble across and/or learn the hard way whilst tackling my own projects.
Moments that I fell in love with Lua
- When I (at least I think I did) grokked tables in Lua. It is the wildest data structure that I have seen provided native in a programming language. It is also the only data structure in Lua.
WTF Lua moments
- One-based indexing. I have used other one-based indexing languages (Cobol, Awk, R) and there are a bunch of languages that are one-based, it’s just that the vast majority of programming that I do is on zero-based indexing languages and I just keep forgetting when I come back to Lua. It’s a legitimate language design choice and I don’t think I’m for or against it (although I have not really stopped to think about it too much). It is what it is.
- Optional parenthesis on function calls if the function has a single argument and the argument is either a literal string or a table constructor. This tripped me up so many times as a noob when trying to understand other people’s code.
Enjoy your Lua journey
Lua is a ton of fun to learn and it is likely that you will come across Lua used as a scripting language in various tools as you progress through your career. It is also a language you can learn easily enough when you need to, so there is no need to go and learn Lua without a need, but I did find it educational to work with a language designed to be embedded and the table data structure got me thinking a lot about language design choices.