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

Method load

components/lua/storage.cpp:255–279  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

253 }
254
255 void LuaStorage::load(lua_State* state, const std::filesystem::path& path)
256 {
257 assert(mData.empty()); // Shouldn't be used before loading
258 try
259 {
260 std::uintmax_t fileSize = std::filesystem::file_size(path);
261 Log(Debug::Info) << "Loading Lua storage \"" << path << "\" (" << fileSize << " bytes)";
262 if (fileSize == 0)
263 throw std::runtime_error("Storage file has zero length");
264
265 std::ifstream fin(path, std::fstream::binary);
266 std::string serializedData((std::istreambuf_iterator<char>(fin)), std::istreambuf_iterator<char>());
267 sol::table data = deserialize(state, serializedData);
268 for (const auto& [sectionName, sectionTable] : data)
269 {
270 const std::shared_ptr<Section>& section = getSection(cast<std::string_view>(sectionName));
271 for (const auto& [key, value] : cast<sol::table>(sectionTable))
272 section->set(cast<std::string_view>(key), value);
273 }
274 }
275 catch (std::exception& e)
276 {
277 Log(Debug::Error) << "Cannot read \"" << path << "\": " << e.what();
278 }
279 }
280
281 void LuaStorage::save(lua_State* state, const std::filesystem::path& path) const
282 {

Callers 4

loadScriptAndCacheMethod · 0.45
loadFromVFSMethod · 0.45
loadInternalLibMethod · 0.45
initUtilPackageFunction · 0.45

Calls 5

LogClass · 0.85
deserializeFunction · 0.70
emptyMethod · 0.45
setMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected