diff options
author | RichieSams | 2014-12-30 15:11:17 -0600 |
---|---|---|
committer | RichieSams | 2014-12-30 15:40:33 -0600 |
commit | 8668707f160fa171edfa68df036f28c7ba4e9a88 (patch) | |
tree | 9e448d82b9469a6e7ad9cfca8b06628092b5269d /engines | |
parent | 08e3f21a8df184bc697e6c03adf968d0cbdbac21 (diff) | |
download | scummvm-rg350-8668707f160fa171edfa68df036f28c7ba4e9a88.tar.gz scummvm-rg350-8668707f160fa171edfa68df036f28c7ba4e9a88.tar.bz2 scummvm-rg350-8668707f160fa171edfa68df036f28c7ba4e9a88.zip |
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
Diffstat (limited to 'engines')
-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); |