Deserializing Lua coroutines with Pluto

Started by
3 comments, last by eriatarka 15 years, 6 months ago
I've just looked at Pluto a bit, and it seems to be a very nice solution for serializing game state to a file. There's one point I don't understand about it though. The documentation says that Pluto can serialize coroutines. If I create a coroutine from C via lua_newthread(), it returns a pointer to a lua_State which represents the new coroutine's call stack, as I understand it. So if I serialize the coroutine and then deserialize it again, how do I recover this lua_State pointer so that I may resume the coroutine from C? I'm thankful for any hints; I think the author of Pluto is on this forum, so I hoped there'd be a good chance to get an answer.
Advertisement
You'll have to the use Lua registry to keep a referable tag for the cororotine around I suspect, of just give it a global tag if you don't mind having the rest of Lua know about the coroutine.

-ddn
Quote:Original post by ddn3
You'll have to the use Lua registry to keep a referable tag for the cororotine around I suspect, of just give it a global tag if you don't mind having the rest of Lua know about the coroutine.

-ddn


I understand that, yes, and that takes care of tracking the Lua-side part of the coroutine. But how do I get the lua_State pointer back which I originally obtain when calling lua_newthread()? I can hardly store that in the Lua registry since it's a C pointer which will no longer be valid after deserialization.
Use the lua_tothread function.
Thanks man, that's exactly what I was looking for! Cheers! :)

This topic is closed to new replies.

Advertisement