Learning Lua

posted 03 May 2020



As mentioned in my PlayDate post, I’ve started learning Lua. My only previous exposure to Lua was though a coworker who had less than glowing things to say about it. Generally, I’m not the biggest fan of languages that 1) employ garbage collection for memory management or 2) don’t compile (scripting languages). Lua does/is both of those things. However, the peope at Panic recomend using the Lua APIs instead of the lower level C APIs, as Lua would be better supported and more robust. And so I started learning Lua.

First impressions: I actually really like it.

I can see there’s some jank to it. The biggest issue I see is the lack of a real array type; everything is a table instead. The major issue is when some item in the array gets set to nil, and the size returned for your array is now wrong. Perhaps worse is when you add one item to the back of the ‘array’, and you happend to bump into another section of contiguous memory. Now your array just got a lot longer and contains a bunch of unrelated data. The solution might be to implement a custom vector type. I havn’t come across a need for an array (where a table wouldn’t do) in my short useage of Lua, so I guess I’ll cross that bridge when I get there.

But despite the wierdness, I’m actually liking it. We will see if that changes once I have to develop a whole game in Lua.

I did also stumble across LuaJIT (Lua Just-In-Time), which comes with some crazy performance gains. I might end up using that if it plays nice with the PlayDate.