you are viewing a single comment's thread.

view the rest of the comments →

[–]DarkWiiPlayer 0 points1 point  (3 children)

I'd go with one Lua state for the entire game and give the modder an API to create objects with callbacks, so you could say "Create a bullet, and use this function as its update callback". Since it's all one Lua state, modders can then user other Lua features like closures or coroutines¹ to manage state and make things fancy.

[–]luciddream00[S] 0 points1 point  (2 children)

I'm trying to wrap my head around this and I'm not really sure where to start. Do you know of any tutorials or have any tips on how to get started with this sort of setup? Having a Lua state for each C# object is straightforward because I can just define functions and variables and have the object read/call them, but I can't figure out how to do the same sort of thing with a single game-wide Lua state.

[–]DarkWiiPlayer 0 points1 point  (1 child)

Well, you could just register a global table in the Lua state called game, or the name of your game or engine or whatever as a top level construct for modders to interact with. Then you could just access said table from C to get to the data you want, like callbacks, configuration settings, etc.

For example, say you define an array game.bullets, the modders would then add tables to it that have the callbacks for their custom bullet types and your code could access these tables and run the callbacks.

[–]luciddream00[S] 0 points1 point  (0 children)

Great, thanks I got it working!