Discussion Imagine Making game engine With Lua
Imagine building a 3D or 2D game engine from scratch using only Lua
0
Upvotes
Imagine building a 3D or 2D game engine from scratch using only Lua
6
u/CapsAdmin Mar 28 '26
I've been doing something like this with LuaJIT and FFI to only use Lua for a about 15 years (on and off). I have a hard rule that I'm not allowed to write and compile any C code of my own. I'm not sure if I'd call it a game engine, but more like framework and a little bit of engine, made only for myself to use.
It started with writing (automated to some extent) C headers to use with FFI bindings to libraries like SDL, OpenGL, OpenAL, bullet physics, libpng, luasocket, etc.
However in my experience, it was very difficult to maintain. I tried precompiling the libraries for other platforms, but not all of the libraries compile into shared libraries by default, so I had to maintain specific build files for each library. Also super painful on Windows. Even Linux to some extent with glibc version mismatches.
Lately I decided to redo the project and add another hard rule; no shared library dependencies except for Vulkan and the OS's native C api.
The biggest general hurdle when it comes to LuaJIT is just dealing with performance and tuning code to work well with its JIT compiler.
old version: https://github.com/CapsAdmin/goluwa (i'd say broken/bit rotten at this point)
rewrite: https://github.com/CapsAdmin/goluwa3
I'm not sure why I'm doing this really. I have no long term plans to make a game or anything, I just like to mess around with realtime rendering.
But one could use some pieces of this (the new version) to build a game engine only using LuaJIT. I try to keep the bindings in https://github.com/CapsAdmin/goluwa3/tree/main/goluwa/bindings independent from my framework/engine so it should be mostly copy pastable for you to make something less bloated.
But if you don't care about "everything must be lua" like me for some reason, then it's better to write everything in a fast statically compiled language and expose high level api's to lua for scripting.
3
u/Several-Union-3075 Mar 28 '26
bro knows something we dont
4
u/weather_isnt_real Mar 28 '26
Lua is not capable of doing that on its own. The engine would have to be written in C/C++, and Lua would be embedded within it. There are already engines that do this.
2
u/Alaska-Kid Mar 28 '26
Well, if we simplify certain aspects and render through the terminal in the form of ASCII, it is quite possible.
2
u/VidaOnce Mar 28 '26 edited Mar 28 '26
I did this with a painting program - https://github.com/codebycruz/arisu.
Everything about it was created from scratch in LuaJIT. It uses X11 or Windows APIs to create a Window, and manually creates Vulkan and OpenGL bindings to render to it. UI layout library and text rendering from scratch as well.
I expose the renderer as a library anyone can use: https://github.com/codebycruz/hood
And I plan on creating a framework similar to love2d or raylib to allow for creation of games relatively easily built off of it while supporting 3D and being faster.
None of this is super production ready, but I built a package manager for Lua that it all builds upon that I can consider production ready: https://lde.sh
1
u/UnrealJIT Mar 28 '26
Lua was never made to act as a foundation for any complex program. I think it's foolish to think otherwise.
LuaJIT makes it more believable to create a game engine. But you'll be calling C code. So not only lua.
Are you willing to trust a just-in-time compiler to build performance-first software from the ground up? I'm not: it's risky, you'll find yourself hitting not-yet-implemented functionalities easily.
1
u/[deleted] Apr 17 '26
shakespeare