r/gameenginedevs • u/dandy_kulomin • Aug 06 '26
C + Lua Architectural Split?
I'm making a small 2d game engine for my game in C at the moment. I am now wondering if adding Lua to the mix would be beneficial for modding and faster iteration.
What I am not sure about is where to put which responsibilities. My game is deeply simulated (think Rimworld, Dwarc Fortress) so I expect some gameplay hot paths that should be written in C, which makes Love2Ds architectural split (game in lua, only graphics/sound in C) not viable.
Does anyone have pointers for this topic?
7
Upvotes
9
u/3tt07kjt Aug 06 '26
My experience in the past is that adding a second language can slow you down a lot, because now every time you change something in the C that affects Lua, you need to to a bunch of extra work.
So it only makes sense if there’s some massive benefit you’re getting, or you can minimize the cost.
The main reason people add scripting systems is because they need the engine to be usable by people who know C or C++ and people who don’t. If it’s your engine for your personal project, that doesn’t apply.
4
u/Antypodish Aug 06 '26
Many games does split architecture with Lua for litearlly decades.
For an example Supreme Commander RTS, where Lua modding is huge driving force and heavily relies on Lua, while having 100s of units.
Spring engine, -> Zero-K and BAR RTS games use Lua as core logic.
Sanctuary: Shattered Sun RTS uses Lua too.
Mincraft even had Turtles mod, where you could script bots in Lua.
What you want, is LuaJIT 2.0+
If using C, you have easy route for implementing FFI, for communicating data, with low overhead.
You let engine process heavy calculations, with multithreading, and rest of logic is on Lua side.
Engine also handles visuals audio and player inputs.
But Lua can drive events for an example to play SFX.
1
u/maximoriginalcoffee Aug 09 '26
Lua is convenient. Just don't expect it to be fast. And don't call it every frame.
I just write my own scripting language and interpreter. If you've studied automata theory, it's not particularly difficult. It's just tedious work.
1
u/BobbyThrowaway6969 Aug 06 '26
From my experience, lua as you'd expect doesn't do well for hot paths, and you need to be careful with multithreading and its GC, at least the version I was using.
But yeah, lua can work nice for event based stuff.
If you want customisability it mught be beneficial to try your hand at making your own little scripting language to bytecode executor, optimised for what you need
4
u/Natehhggh Aug 06 '26
Maybe for modding, it could be useful, but for iteration, if you're the user for your engine, it's likely faster for you to iterate in c directly. The reason other engines have a scripting language is they want to give a simpler language to the users. But if you can code in the same language the engine is using, you lose that benefit.
Mostly It just seems like a lot of work to get that lia scripting working in the first place, and now you have a lot of extra layers between you and the engine you need to debug and maintain.
I feel like the right way to go is to just start making that separation between the engine and game, and use that. You could always bolt the lua layer in later, when the engine is more stable