From 8668707f160fa171edfa68df036f28c7ba4e9a88 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Tue, 30 Dec 2014 15:11:17 -0600 Subject: SWORD25: Fix how nils are persisted The unpersist code expects nils to be represented as an index with value 0. The persist code incorrectly wrote out this data --- engines/sword25/util/lua_persist.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'engines/sword25/util') diff --git a/engines/sword25/util/lua_persist.cpp b/engines/sword25/util/lua_persist.cpp index 939dbf38a8..6d758067ad 100644 --- a/engines/sword25/util/lua_persist.cpp +++ b/engines/sword25/util/lua_persist.cpp @@ -59,7 +59,7 @@ void persistLua(lua_State *luaState, Common::WriteStream *writeStream) { SerializationInfo info; info.luaState = luaState; info.writeStream = writeStream; - info.counter = 0u; + info.counter = 1u; // The process starts with the lua stack as follows: // >>>>> permTbl rootObj @@ -145,19 +145,22 @@ static void serialize(SerializationInfo *info) { return; } - // Pop the nil off the stack + // Pop the index/nil off the stack lua_pop(info->luaState, 1); - // Write out a flag that indicates that this is a real object - info->writeStream->writeByte(1); - - // If the object itself is nil, then write out a zero as a placeholder + // If the obj itself is nil, we represent it as an index of 0 if (lua_isnil(info->luaState, -1)) { + // Write out a flag that indicates that it's an index info->writeStream->writeByte(0); + // Write out the index + info->writeStream->writeUint32LE(0); return; } + // Write out a flag that indicates that this is a real object + info->writeStream->writeByte(1); + // Add the object to the indexTbl lua_pushvalue(info->luaState, -1); -- cgit v1.2.3