diff options
-rw-r--r-- | engines/sword25/util/lua_persist.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
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); |