| 402 | } |
| 403 | |
| 404 | sol::function LuaState::loadScriptAndCache(const VFS::Path::Normalized& path) |
| 405 | { |
| 406 | auto iter = mCompiledScripts.find(path); |
| 407 | if (iter != mCompiledScripts.end()) |
| 408 | { |
| 409 | sol::load_result res = mSol.load(iter->second.as_string_view(), path.value(), sol::load_mode::binary); |
| 410 | // Unless we have memory corruption issues, the bytecode is valid at this point, but loading might still |
| 411 | // fail because we've hit our Lua memory cap |
| 412 | if (!res.valid()) |
| 413 | throw std::runtime_error("Lua error: " + res.get<std::string>()); |
| 414 | return res; |
| 415 | } |
| 416 | sol::function res = loadFromVFS(path); |
| 417 | mCompiledScripts[path] = res.dump(); |
| 418 | return res; |
| 419 | } |
| 420 | |
| 421 | sol::function LuaState::loadFromVFS(const VFS::Path::Normalized& path) |
| 422 | { |