diff options
-rw-r--r-- | engines/sword25/util/lua_persist.cpp | 98 | ||||
-rw-r--r-- | engines/sword25/util/lua_unpersist.cpp | 102 |
2 files changed, 100 insertions, 100 deletions
diff --git a/engines/sword25/util/lua_persist.cpp b/engines/sword25/util/lua_persist.cpp index aea4e70036..6038111bbc 100644 --- a/engines/sword25/util/lua_persist.cpp +++ b/engines/sword25/util/lua_persist.cpp @@ -66,17 +66,17 @@ struct SerializationInfo { uint counter; }; -static void serialize(SerializationInfo *info); +static void persist(SerializationInfo *info); -static void serializeBoolean(SerializationInfo *info); -static void serializeNumber(SerializationInfo *info); -static void serializeString(SerializationInfo *info); -static void serializeTable(SerializationInfo *info); -static void serializeFunction(SerializationInfo *info); -static void serializeThread(SerializationInfo *info); -static void serializeProto(SerializationInfo *info); -static void serializeUpValue(SerializationInfo *info); -static void serializeUserData(SerializationInfo *info); +static void persistBoolean(SerializationInfo *info); +static void persistNumber(SerializationInfo *info); +static void persistString(SerializationInfo *info); +static void persistTable(SerializationInfo *info); +static void persistFunction(SerializationInfo *info); +static void persistThread(SerializationInfo *info); +static void persistProto(SerializationInfo *info); +static void persistUpValue(SerializationInfo *info); +static void persistUserData(SerializationInfo *info); void persistLua(lua_State *luaState, Common::WriteStream *writeStream) { @@ -127,14 +127,14 @@ void persistLua(lua_State *luaState, Common::WriteStream *writeStream) { // >>>>> permTbl indexTbl rootObj // Serialize the root recursively - serialize(&info); + persist(&info); // Return the stack back to the original state lua_remove(luaState, 2); // >>>>> permTbl rootObj } -static void serialize(SerializationInfo *info) { +static void persist(SerializationInfo *info) { // The stack can potentially have many things on it // The object we want to serialize is the item on the top of the stack // >>>>> permTbl indexTbl rootObj ...... obj @@ -215,7 +215,7 @@ static void serialize(SerializationInfo *info) { info->writeStream->writeSint32LE(PERMANENT_TYPE); // Serialize the key - serialize(info); + persist(info); // Pop the key off the stack lua_pop(info->luaState, 1); @@ -236,7 +236,7 @@ static void serialize(SerializationInfo *info) { switch (objType) { case LUA_TBOOLEAN: - serializeBoolean(info); + persistBoolean(info); break; case LUA_TLIGHTUSERDATA: // You can't serialize a pointer @@ -244,41 +244,41 @@ static void serialize(SerializationInfo *info) { assert(0); break; case LUA_TNUMBER: - serializeNumber(info); + persistNumber(info); break; case LUA_TSTRING: - serializeString(info); + persistString(info); break; case LUA_TTABLE: - serializeTable(info); + persistTable(info); break; case LUA_TFUNCTION: - serializeFunction(info); + persistFunction(info); break; case LUA_TTHREAD: - serializeThread(info); + persistThread(info); break; case LUA_TPROTO: - serializeProto(info); + persistProto(info); break; case LUA_TUPVAL: - serializeUpValue(info); + persistUpValue(info); break; case LUA_TUSERDATA: - serializeUserData(info); + persistUserData(info); break; default: assert(0); } } -static void serializeBoolean(SerializationInfo *info) { +static void persistBoolean(SerializationInfo *info) { int value = lua_toboolean(info->luaState, -1); info->writeStream->writeSint32LE(value); } -static void serializeNumber(SerializationInfo *info) { +static void persistNumber(SerializationInfo *info) { lua_Number value = lua_tonumber(info->luaState, -1); #if 1 @@ -298,7 +298,7 @@ static void serializeNumber(SerializationInfo *info) { } -static void serializeString(SerializationInfo *info) { +static void persistString(SerializationInfo *info) { // Hard cast to a uint32 to force size_t to an explicit size // *Theoretically* this could truncate, but if we have a 4gb string, we have bigger problems uint32 length = static_cast<uint32>(lua_strlen(info->luaState, -1)); @@ -395,7 +395,7 @@ static bool serializeSpecialObject(SerializationInfo *info, bool defaction) { info->writeStream->writeSint32LE(1); // Serialize the function - serialize(info); + persist(info); lua_pop(info->luaState, 2); // >>>>> permTbl indexTbl ...... obj @@ -403,7 +403,7 @@ static bool serializeSpecialObject(SerializationInfo *info, bool defaction) { return true; } -static void serializeTable(SerializationInfo *info) { +static void persistTable(SerializationInfo *info) { // >>>>> permTbl indexTbl ...... tbl // Make sure there is enough room on the stack @@ -422,7 +422,7 @@ static void serializeTable(SerializationInfo *info) { } // >>>>> permTbl indexTbl ...... tbl metaTbl/nil */ - serialize(info); + persist(info); lua_pop(info->luaState, 1); // >>>>> permTbl indexTbl ...... tbl @@ -439,13 +439,13 @@ static void serializeTable(SerializationInfo *info) { // >>>>> permTbl indexTbl ...... tbl k v k */ // Serialize the key - serialize(info); + persist(info); lua_pop(info->luaState, 1); // >>>>> permTbl indexTbl ...... tbl k v */ // Serialize the value - serialize(info); + persist(info); lua_pop(info->luaState, 1); // >>>>> permTbl indexTbl ...... tbl k */ @@ -457,13 +457,13 @@ static void serializeTable(SerializationInfo *info) { lua_pushnil(info->luaState); // >>>>> permTbl indexTbl ...... tbl - serialize(info); + persist(info); lua_pop(info->luaState, 1); // >>>>> permTbl indexTbl ...... tbl } -static void serializeFunction(SerializationInfo *info) { +static void persistFunction(SerializationInfo *info) { // >>>>> permTbl indexTbl ...... func Closure *cl = clvalue(getObject(info->luaState, -1)); lua_checkstack(info->luaState, 2); @@ -484,7 +484,7 @@ static void serializeFunction(SerializationInfo *info) { pushProto(info->luaState, cl->l.p); // >>>>> permTbl indexTbl ...... func proto */ - serialize(info); + persist(info); lua_pop(info->luaState, 1); // >>>>> permTbl indexTbl ...... func @@ -495,7 +495,7 @@ static void serializeFunction(SerializationInfo *info) { pushUpValue(info->luaState, cl->l.upvals[i]); // >>>>> permTbl indexTbl ...... func upval - serialize(info); + persist(info); lua_pop(info->luaState, 1); // >>>>> permTbl indexTbl ...... func @@ -519,14 +519,14 @@ static void serializeFunction(SerializationInfo *info) { } // >>>>> permTbl indexTbl ...... func fenv/nil - serialize(info); + persist(info); lua_pop(info->luaState, 1); // >>>>> permTbl indexTbl ...... func } } -static void serializeThread(SerializationInfo *info) { +static void persistThread(SerializationInfo *info) { // >>>>> permTbl indexTbl ...... thread lua_State *threadState = lua_tothread(info->luaState, -1); @@ -547,7 +547,7 @@ static void serializeThread(SerializationInfo *info) { // >>>>> permTbl indexTbl ...... thread (reversed contents of thread stack) */ for (; stackSize > 0; --stackSize) { - serialize(info); + persist(info); lua_pop(info->luaState, 1); } @@ -609,7 +609,7 @@ static void serializeThread(SerializationInfo *info) { pushUpValue(info->luaState, upVal); // >>>>> permTbl indexTbl ...... thread upVal - serialize(info); + persist(info); lua_pop(info->luaState, 1); // >>>>> permTbl indexTbl ...... thread @@ -624,13 +624,13 @@ static void serializeThread(SerializationInfo *info) { // >>>>> permTbl indexTbl ...... thread nil // Use nil as a terminator - serialize(info); + persist(info); lua_pop(info->luaState, 1); // >>>>> permTbl indexTbl ...... thread } -static void serializeProto(SerializationInfo *info) { +static void persistProto(SerializationInfo *info) { // >>>>> permTbl indexTbl ...... proto Proto *proto = gco2p(getObject(info->luaState, -1)->value.gc); @@ -644,7 +644,7 @@ static void serializeProto(SerializationInfo *info) { pushObject(info->luaState, &proto->k[i]); // >>>>> permTbl indexTbl ...... proto const - serialize(info); + persist(info); lua_pop(info->luaState, 1); // >>>>> permTbl indexTbl ...... proto @@ -660,7 +660,7 @@ static void serializeProto(SerializationInfo *info) { pushProto(info->luaState, proto->p[i]); // >>>>> permTbl indexTbl ...... proto subProto */ - serialize(info); + persist(info); lua_pop(info->luaState, 1); // >>>>> permTbl indexTbl ...... proto @@ -683,7 +683,7 @@ static void serializeProto(SerializationInfo *info) { pushString(info->luaState, proto->upvalues[i]); // >>>>> permTbl indexTbl ...... proto str - serialize(info); + persist(info); lua_pop(info->luaState, 1); // >>>>> permTbl indexTbl ...... proto @@ -697,7 +697,7 @@ static void serializeProto(SerializationInfo *info) { pushString(info->luaState, proto->locvars[i].varname); // >>>>> permTbl indexTbl ...... proto str - serialize(info); + persist(info); lua_pop(info->luaState, 1); // >>>>> permTbl indexTbl ...... proto @@ -711,7 +711,7 @@ static void serializeProto(SerializationInfo *info) { pushString(info->luaState, proto->source); // >>>>> permTbl indexTbl ...... proto sourceStr - serialize(info); + persist(info); lua_pop(info->luaState, 1); // >>>>> permTbl indexTbl ...... proto @@ -757,7 +757,7 @@ static void serializeProto(SerializationInfo *info) { * (d) When unserializing, "reopen" each of these upvalues as the thread is * unserialized */ -static void serializeUpValue(SerializationInfo *info) { +static void persistUpValue(SerializationInfo *info) { // >>>>> permTbl indexTbl ...... upval assert(ttype(getObject(info->luaState, -1)) == LUA_TUPVAL); UpVal *upValue = gco2uv(getObject(info->luaState, -1)->value.gc); @@ -774,11 +774,11 @@ static void serializeUpValue(SerializationInfo *info) { pushObject(info->luaState, upValue->v); // >>>>> permTbl indexTbl ...... obj - serialize(info); + persist(info); // >>>>> permTbl indexTbl ...... obj } -static void serializeUserData(SerializationInfo *info) { +static void persistUserData(SerializationInfo *info) { // >>>>> permTbl rootObj ...... udata // Make sure there is enough room on the stack @@ -804,7 +804,7 @@ static void serializeUserData(SerializationInfo *info) { } // >>>>> permTbl rootObj ...... udata metaTbl/nil - serialize(info); + persist(info); lua_pop(info->luaState, 1); /* perms reftbl ... udata */ diff --git a/engines/sword25/util/lua_unpersist.cpp b/engines/sword25/util/lua_unpersist.cpp index 6f3275741a..ef0ef31041 100644 --- a/engines/sword25/util/lua_unpersist.cpp +++ b/engines/sword25/util/lua_unpersist.cpp @@ -64,18 +64,18 @@ struct UnSerializationInfo { Common::ReadStream *readStream; }; -static void unserialize(UnSerializationInfo *info); +static void unpersist(UnSerializationInfo *info); -static void unserializeBoolean(UnSerializationInfo *info); -static void unserializeNumber(UnSerializationInfo *info); -static void unserializeString(UnSerializationInfo *info); -static void unserializeTable(UnSerializationInfo *info, int index); -static void unserializeFunction(UnSerializationInfo *info, int index); -static void unserializeThread(UnSerializationInfo *info, int index); -static void unserializeProto(UnSerializationInfo *info, int index); -static void unserializeUpValue(UnSerializationInfo *info, int index); -static void unserializeUserData(UnSerializationInfo *info, int index); -static void unserializePermanent(UnSerializationInfo *info, int index); +static void unpersistBoolean(UnSerializationInfo *info); +static void unpersistNumber(UnSerializationInfo *info); +static void unpersistString(UnSerializationInfo *info); +static void unpersistTable(UnSerializationInfo *info, int index); +static void unpersistFunction(UnSerializationInfo *info, int index); +static void unpersistThread(UnSerializationInfo *info, int index); +static void unpersistProto(UnSerializationInfo *info, int index); +static void unpersistUpValue(UnSerializationInfo *info, int index); +static void unpersistUserData(UnSerializationInfo *info, int index); +static void unpersistPermanent(UnSerializationInfo *info, int index); void unpersistLua(lua_State *luaState, Common::ReadStream *readStream) { @@ -98,7 +98,7 @@ void unpersistLua(lua_State *luaState, Common::ReadStream *readStream) { lua_gc(luaState, LUA_GCSTOP, 0); // Unserialize the root object - unserialize(&info); + unpersist(&info); // >>>>> permTbl indexTbl rootObj // Re-start garbage collection @@ -129,7 +129,7 @@ static void registerObjectInIndexTable(UnSerializationInfo *info, int index) { // >>>>> permTbl indexTbl ...... obj } -static void unserialize(UnSerializationInfo *info) { +static void unpersist(UnSerializationInfo *info) { // >>>>> permTbl indexTbl ...... // Make sure there is enough room on the stack @@ -142,7 +142,7 @@ static void unserialize(UnSerializationInfo *info) { switch (type) { case LUA_TBOOLEAN: - unserializeBoolean(info); + unpersistBoolean(info); break; case LUA_TLIGHTUSERDATA: // You can't serialize a pointer @@ -150,31 +150,31 @@ static void unserialize(UnSerializationInfo *info) { assert(0); break; case LUA_TNUMBER: - unserializeNumber(info); + unpersistNumber(info); break; case LUA_TSTRING: - unserializeString(info); + unpersistString(info); break; case LUA_TTABLE: - unserializeTable(info, index); + unpersistTable(info, index); break; case LUA_TFUNCTION: - unserializeFunction(info, index); + unpersistFunction(info, index); break; case LUA_TTHREAD: - unserializeThread(info, index); + unpersistThread(info, index); break; case LUA_TPROTO: - unserializeProto(info, index); + unpersistProto(info, index); break; case LUA_TUPVAL: - unserializeUpValue(info, index); + unpersistUpValue(info, index); break; case LUA_TUSERDATA: - unserializeUserData(info, index); + unpersistUserData(info, index); break; case PERMANENT_TYPE: - unserializePermanent(info, index); + unpersistPermanent(info, index); break; default: assert(0); @@ -212,7 +212,7 @@ static void unserialize(UnSerializationInfo *info) { // >>>>> permTbl indexTbl ...... obj/nil } -static void unserializeBoolean(UnSerializationInfo *info) { +static void unpersistBoolean(UnSerializationInfo *info) { // >>>>> permTbl indexTbl ...... // Make sure there is enough room on the stack @@ -224,7 +224,7 @@ static void unserializeBoolean(UnSerializationInfo *info) { // >>>>> permTbl indexTbl ...... bool } -static void unserializeNumber(UnSerializationInfo *info) { +static void unpersistNumber(UnSerializationInfo *info) { // >>>>> permTbl indexTbl ...... // Make sure there is enough room on the stack @@ -242,7 +242,7 @@ static void unserializeNumber(UnSerializationInfo *info) { // >>>>> permTbl indexTbl ...... num } -static void unserializeString(UnSerializationInfo *info) { +static void unpersistString(UnSerializationInfo *info) { // >>>>> permTbl indexTbl ...... // Make sure there is enough room on the stack @@ -265,7 +265,7 @@ static void unserializeSpecialTable(UnSerializationInfo *info, int index) { // Make sure there is enough room on the stack lua_checkstack(info->luaState, 1); - unserialize(info); + unpersist(info); // >>>>> permTbl indexTbl ...... spfunc lua_call(info->luaState, 0, 1); @@ -286,7 +286,7 @@ static void unserializeLiteralTable(UnSerializationInfo *info, int index) { // >>>>> permTbl indexTbl ...... tbl // Unserialize metatable - unserialize(info); + unpersist(info); // >>>>> permTbl indexTbl ...... tbl ?metaTbl/nil? if (lua_istable(info->luaState, -1)) { @@ -303,7 +303,7 @@ static void unserializeLiteralTable(UnSerializationInfo *info, int index) { while (1) { // >>>>> permTbl indexTbl ...... tbl - unserialize(info); + unpersist(info); // >>>>> permTbl indexTbl ...... tbl key/nil // The table serialization is nil terminated @@ -316,7 +316,7 @@ static void unserializeLiteralTable(UnSerializationInfo *info, int index) { } // >>>>> permTbl indexTbl ...... tbl key - unserialize(info); + unpersist(info); // >>>>> permTbl indexTbl ...... tbl value lua_rawset(info->luaState, -3); @@ -324,7 +324,7 @@ static void unserializeLiteralTable(UnSerializationInfo *info, int index) { } } -void unserializeTable(UnSerializationInfo *info, int index) { +void unpersistTable(UnSerializationInfo *info, int index) { // >>>>> permTbl indexTbl ...... // Make sure there is enough room on the stack @@ -341,7 +341,7 @@ void unserializeTable(UnSerializationInfo *info, int index) { } } -void unserializeFunction(UnSerializationInfo *info, int index) { +void unpersistFunction(UnSerializationInfo *info, int index) { // >>>>> permTbl indexTbl ...... // Make sure there is enough room on the stack @@ -372,7 +372,7 @@ void unserializeFunction(UnSerializationInfo *info, int index) { registerObjectInIndexTable(info, index); // Now that it's safe, we can get the real proto - unserialize(info); + unpersist(info); // >>>>> permTbl indexTbl ...... func proto lclosure->p = gco2p(getObject(info->luaState, -1)->value.gc); @@ -382,7 +382,7 @@ void unserializeFunction(UnSerializationInfo *info, int index) { for (byte i = 0; i < numUpValues; ++i) { // >>>>> permTbl indexTbl ...... func - unserialize(info); + unpersist(info); // >>>>> permTbl indexTbl ...... func func2 unboxUpValue(info->luaState); @@ -394,7 +394,7 @@ void unserializeFunction(UnSerializationInfo *info, int index) { } // Finally, the fenv - unserialize(info); + unpersist(info); // >>>>> permTbl indexTbl ...... func ?fenv/nil? if (!lua_isnil(info->luaState, -1)) { @@ -410,7 +410,7 @@ void unserializeFunction(UnSerializationInfo *info, int index) { // >>>>> permTbl indexTbl ...... func } -void unserializeThread(UnSerializationInfo *info, int index) { +void unpersistThread(UnSerializationInfo *info, int index) { // >>>>> permTbl indexTbl ...... lua_State *L2; @@ -432,7 +432,7 @@ void unserializeThread(UnSerializationInfo *info, int index) { // very bottom of the stack L2->top--; for (uint32 i = 0; i < stackSize; ++i) { - unserialize(info); + unpersist(info); // L1: permTbl indexTbl ...... thread obj* } @@ -492,7 +492,7 @@ void unserializeThread(UnSerializationInfo *info, int index) { global_State *g = G(L2); while (true) { - unserialize(info); + unpersist(info); // >>>>> permTbl indexTbl ...... thread upVal/nil // The list is terminated by a nil @@ -535,7 +535,7 @@ void unserializeThread(UnSerializationInfo *info, int index) { } } -void unserializeProto(UnSerializationInfo *info, int index) { +void unpersistProto(UnSerializationInfo *info, int index) { // >>>>> permTbl indexTbl ...... // We have to be careful. The GC expects a lot out of protos. In particular, we need @@ -564,7 +564,7 @@ void unserializeProto(UnSerializationInfo *info, int index) { lua_reallocvector(info->luaState, p->k, 0, sizek, TValue); for (int i = 0; i < sizek; ++i) { // >>>>> permTbl indexTbl ...... proto - unserialize(info); + unpersist(info); // >>>>> permTbl indexTbl ...... proto k setobj2s(info->luaState, &p->k[i], getObject(info->luaState, -1)); @@ -581,7 +581,7 @@ void unserializeProto(UnSerializationInfo *info, int index) { lua_reallocvector(info->luaState, p->p, 0, sizep, Proto *); for (int i = 0; i < sizep; ++i) { // >>>>> permTbl indexTbl ...... proto - unserialize(info); + unpersist(info); // >>>>> permTbl indexTbl ...... proto subproto p->p[i] = (Proto *)getObject(info->luaState, -1)->value.gc; @@ -605,7 +605,7 @@ void unserializeProto(UnSerializationInfo *info, int index) { lua_reallocvector(info->luaState, p->upvalues, 0, p->sizeupvalues, TString *); for (int i = 0; i < p->sizeupvalues; ++i) { // >>>>> permTbl indexTbl ...... proto - unserialize(info); + unpersist(info); // >>>>> permTbl indexTbl ...... proto str p->upvalues[i] = lua_newlstr(info->luaState, lua_tostring(info->luaState, -1), strlen(lua_tostring(info->luaState, -1))); @@ -621,7 +621,7 @@ void unserializeProto(UnSerializationInfo *info, int index) { lua_reallocvector(info->luaState, p->locvars, 0, p->sizelocvars, LocVar); for (int i = 0; i < p->sizelocvars; ++i) { // >>>>> permTbl indexTbl ...... proto - unserialize(info); + unpersist(info); // >>>>> permTbl indexTbl ...... proto str p->locvars[i].varname = lua_newlstr(info->luaState, lua_tostring(info->luaState, -1), strlen(lua_tostring(info->luaState, -1))); @@ -635,7 +635,7 @@ void unserializeProto(UnSerializationInfo *info, int index) { // >>>>> permTbl indexTbl ...... proto // Read in source string - unserialize(info); + unpersist(info); // >>>>> permTbl indexTbl ...... proto sourceStr p->source = lua_newlstr(info->luaState, lua_tostring(info->luaState, -1), strlen(lua_tostring(info->luaState, -1))); @@ -661,7 +661,7 @@ void unserializeProto(UnSerializationInfo *info, int index) { p->maxstacksize = info->readStream->readByte(); } -void unserializeUpValue(UnSerializationInfo *info, int index) { +void unpersistUpValue(UnSerializationInfo *info, int index) { // >>>>> permTbl indexTbl ...... lua_checkstack(info->luaState, 2); @@ -669,14 +669,14 @@ void unserializeUpValue(UnSerializationInfo *info, int index) { // >>>>> permTbl indexTbl ...... func registerObjectInIndexTable(info, index); - unserialize(info); + unpersist(info); // >>>>> permTbl indexTbl ...... func obj boxUpValue_finish(info->luaState); // >>>>> permTbl indexTbl ...... func } -void unserializeUserData(UnSerializationInfo *info, int index) { +void unpersistUserData(UnSerializationInfo *info, int index) { // >>>>> permTbl indexTbl ...... // Make sure there is enough room on the stack @@ -684,7 +684,7 @@ void unserializeUserData(UnSerializationInfo *info, int index) { int isspecial = info->readStream->readSint32LE(); if (isspecial) { - unserialize(info); + unpersist(info); // >>>>> permTbl indexTbl ...... specialFunc lua_call(info->luaState, 0, 1); @@ -697,7 +697,7 @@ void unserializeUserData(UnSerializationInfo *info, int index) { info->readStream->read(lua_touserdata(info->luaState, -1), length); - unserialize(info); + unpersist(info); // >>>>> permTbl indexTbl ...... udata metaTable/nil lua_setmetatable(info->luaState, -2); @@ -706,13 +706,13 @@ void unserializeUserData(UnSerializationInfo *info, int index) { // >>>>> permTbl indexTbl ...... udata } -void unserializePermanent(UnSerializationInfo *info, int index) { +void unpersistPermanent(UnSerializationInfo *info, int index) { // >>>>> permTbl indexTbl ...... // Make sure there is enough room on the stack lua_checkstack(info->luaState, 2); - unserialize(info); + unpersist(info); // >>>>> permTbl indexTbl ...... permKey lua_gettable(info->luaState, 1); |