Lua Game Development And Type Safety
I am working on my next game project: Idle Space Factory. It’s a game combining resource management, factory building and trading. I have been using TypeScript for all my games for a while and I couldn’t be more happier. The gradual and structural typing system, plus the powerful type inference make TypeScript a great fit for game development. In the early prototyping phase, I don’t have to bother with the type declarations, since they will change anyway. And when I’ve “found the fun” and start production, I can add the types and enjoy the type safety.
Haxe is probably one of the first transpilers that provide a Lua target. Since Haxe itself has been out for a while and are widely used in game development, the IDE and tooling support is relatively good. Haxe’s language feature and standard library is quite big, therefore the Lua target is a much smaller subset. So using it in a embedded game might not be as straightforward. The transpiled source is hard to read and oftentimes embedded Lua requires exposing certain functions/variables from script as the entrance, this adds to the difficulty.
Teal comes from the author of LuaRocks. It’s relatively new and use a minimalist approach when it comes to adding static typing, which makes is very suitable for using in embedded Lua environment. The language itself has some influence from TypeScript when it comes to introducing a type system for a dynamic language. Since it is quite new, the features are still changing and the IDE/tooling support is still catching up. But even using it as is, it already provides benefits to existing Lua codebase.
It’s been a while since I work with Lua and I am definitely happier working with TypeScript nowadays. If you are currently working with Lua and want more type safety, I recommended checking these out.