lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I want to use lua to create a game. NPCs for example will be running lua scripts, and events will also be scripted. I'm thinking of implementing the scripts as coroutines that yield whenever they've done the amount of work they want to do during one frame of the game's engine. That way, I only have one lua_State object, and I can call the script engine once per frame, and return back to C.

One difficulty I have is that I need to save the current state of the scripts when the player is saving the game. Given my current lua_State object, I'd like to be able to serialize it to disk together with the rest of my savegame data.

Has anyone written something like this before? I've looked through the lua code this morning before breakfast - it looks like recreating the state object, and registering everything in the right places, is a bit of an adventure, and if anyone has gone that way before, I'd like to not reinvent that particular wheel :-)

Enno.