| 279 | } |
| 280 | |
| 281 | void LuaStorage::save(lua_State* state, const std::filesystem::path& path) const |
| 282 | { |
| 283 | sol::table data(state, sol::create); |
| 284 | for (const auto& [sectionName, section] : mData) |
| 285 | { |
| 286 | if (section->mLifeTime == Section::Persistent && !section->mValues.empty()) |
| 287 | data[sectionName] = section->asTable(state); |
| 288 | } |
| 289 | std::string serializedData = serialize(data); |
| 290 | Log(Debug::Info) << "Saving Lua storage \"" << path << "\" (" << serializedData.size() << " bytes)"; |
| 291 | std::ofstream fout(path, std::fstream::binary); |
| 292 | fout.write(serializedData.data(), serializedData.size()); |
| 293 | fout.close(); |
| 294 | } |
| 295 | |
| 296 | const std::shared_ptr<LuaStorage::Section>& LuaStorage::getSection(std::string_view sectionName) |
| 297 | { |