Comment 2 for bug 536507

Revision history for this message
SirVer (sirver) wrote :

I am not sure how long hanging this is - there is a technical minuita that could make a problem:

Basically, the way I would implement this would be by adding a wl.Game().save() method into the Lua stack or by hooking it into the objective closing method im map (which is also called from inside Lua, so for the argument below there is no difference)[1]. The problem is now that a Lua coroutine that is currently running can not be saved - that is if save() is called from inside a coroutine, the game will crash. But objectives are very likely to be closed from inside a coroutine - so this is bad.

The solution to this is to instead add some state that defers saving until we are back in C++ code - i.e. all Couroutines are sleeping. This must most likely be done via a new variable in Game (something like: save_next_time_you_can). All of this should be fairly easy, but it is not trivial.

[1] There is already a method that saves a game, but it must not be called from a running coroutine or the game will crash.