MCPcopy Create free account
hub / github.com/OpenMW/openmw / serialize

Function serialize

components/lua/serialization.cpp:198–236  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

196 }
197
198 static void serialize(
199 BinaryData& out, const sol::object& obj, const UserdataSerializer* customSerializer, int recursionCounter)
200 {
201 if (obj.get_type() == sol::type::lightuserdata)
202 throw std::runtime_error("Light userdata is not allowed to be serialized.");
203 if (obj.is<sol::function>())
204 throw std::runtime_error("Functions are not allowed to be serialized.");
205 else if (obj.is<sol::userdata>())
206 serializeUserdata(out, obj, customSerializer);
207 else if (obj.is<sol::lua_table>())
208 {
209 if (recursionCounter >= 32)
210 throw std::runtime_error(
211 "Can not serialize more than 32 nested tables. Likely the table contains itself.");
212 sol::table table = obj;
213 appendType(out, SerializedType::TABLE_START);
214 for (auto& [key, value] : table)
215 {
216 serialize(out, key, customSerializer, recursionCounter + 1);
217 serialize(out, value, customSerializer, recursionCounter + 1);
218 }
219 appendType(out, SerializedType::TABLE_END);
220 }
221 else if (obj.is<double>())
222 {
223 appendType(out, SerializedType::NUMBER);
224 appendValue<double>(out, obj.as<double>());
225 }
226 else if (obj.is<std::string_view>())
227 appendString(out, obj.as<std::string_view>());
228 else if (obj.is<bool>())
229 {
230 char v = obj.as<bool>() ? 1 : 0;
231 appendType(out, SerializedType::BOOLEAN);
232 out.push_back(v);
233 }
234 else
235 throw std::runtime_error("Unknown Lua type.");
236 }
237
238 static void deserializeImpl(
239 lua_State* lua, std::string_view& binaryData, const UserdataSerializer* customSerializer, bool readOnly)

Callers 6

saveMethod · 0.70
ValueMethod · 0.70
saveMethod · 0.70
loadMethod · 0.70

Calls 4

serializeUserdataFunction · 0.85
appendTypeFunction · 0.85
appendStringFunction · 0.85
get_typeMethod · 0.45

Tested by

no test coverage detected