!3362 with safe reloadlua

macos_ci_fix
Petr Mikheev 1 year ago
parent 551f424c80
commit 72b8ff82ff

@ -44,6 +44,11 @@ namespace MWLua
return world->isActorCollisionEnabled(world->getPlayerPtr()); return world->isActorCollisionEnabled(world->getPlayerPtr());
}; };
api["toggleMWScript"] = []() { MWBase::Environment::get().getWorld()->toggleScripts(); };
api["isMWScriptEnabled"] = []() { return MWBase::Environment::get().getWorld()->getScriptsEnabled(); };
api["reloadLua"] = []() { MWBase::Environment::get().getLuaManager()->reloadAllScripts(); };
api["NAV_MESH_RENDER_MODE"] api["NAV_MESH_RENDER_MODE"]
= LuaUtil::makeStrictReadOnly(context.mLua->tableFromPairs<std::string_view, MWRender::NavMeshMode>({ = LuaUtil::makeStrictReadOnly(context.mLua->tableFromPairs<std::string_view, MWRender::NavMeshMode>({
{ "AreaType", MWRender::NavMeshMode::AreaType }, { "AreaType", MWRender::NavMeshMode::AreaType },

@ -239,6 +239,13 @@ namespace MWLua
mInGameConsoleMessages.clear(); mInGameConsoleMessages.clear();
applyDelayedActions(); applyDelayedActions();
if (mReloadAllScriptsRequested)
{
// Reloading right after `applyDelayedActions` to guarantee that no delayed actions are currently queued.
reloadAllScriptsImpl();
mReloadAllScriptsRequested = false;
}
} }
void LuaManager::applyDelayedActions() void LuaManager::applyDelayedActions()
@ -477,7 +484,7 @@ namespace MWLua
scripts->load(data); scripts->load(data);
} }
void LuaManager::reloadAllScripts() void LuaManager::reloadAllScriptsImpl()
{ {
Log(Debug::Info) << "Reload Lua"; Log(Debug::Info) << "Reload Lua";

@ -116,8 +116,9 @@ namespace MWLua
void loadLocalScripts(const MWWorld::Ptr& ptr, const ESM::LuaScripts& data) override; void loadLocalScripts(const MWWorld::Ptr& ptr, const ESM::LuaScripts& data) override;
void setContentFileMapping(const std::map<int, int>& mapping) override { mContentFileMapping = mapping; } void setContentFileMapping(const std::map<int, int>& mapping) override { mContentFileMapping = mapping; }
// Drops script cache and reloads all scripts. Calls `onSave` and `onLoad` for every script. // At the end of the next `synchronizedUpdate` drops script cache and reloads all scripts.
void reloadAllScripts() override; // Calls `onSave` and `onLoad` for every script.
void reloadAllScripts() override { mReloadAllScriptsRequested = true; }
void handleConsoleCommand( void handleConsoleCommand(
const std::string& consoleMode, const std::string& command, const MWWorld::Ptr& selectedPtr) override; const std::string& consoleMode, const std::string& command, const MWWorld::Ptr& selectedPtr) override;
@ -149,12 +150,14 @@ namespace MWLua
void initConfiguration(); void initConfiguration();
LocalScripts* createLocalScripts(const MWWorld::Ptr& ptr, LocalScripts* createLocalScripts(const MWWorld::Ptr& ptr,
std::optional<LuaUtil::ScriptIdsWithInitializationData> autoStartConf = std::nullopt); std::optional<LuaUtil::ScriptIdsWithInitializationData> autoStartConf = std::nullopt);
void reloadAllScriptsImpl();
bool mInitialized = false; bool mInitialized = false;
bool mGlobalScriptsStarted = false; bool mGlobalScriptsStarted = false;
bool mProcessingInputEvents = false; bool mProcessingInputEvents = false;
bool mApplyingDelayedActions = false; bool mApplyingDelayedActions = false;
bool mNewGameStarted = false; bool mNewGameStarted = false;
bool mReloadAllScriptsRequested = false;
LuaUtil::ScriptsConfiguration mConfiguration; LuaUtil::ScriptsConfiguration mConfiguration;
LuaUtil::LuaState mLua; LuaUtil::LuaState mLua;
LuaUi::ResourceManager mUiResourceManager; LuaUi::ResourceManager mUiResourceManager;

@ -44,6 +44,19 @@
-- @function [parent=#Debug] isCollisionEnabled -- @function [parent=#Debug] isCollisionEnabled
-- @return #boolean -- @return #boolean
---
-- Toggles MWScripts
-- @function [parent=#Debug] toggleMWScript
---
-- Is MWScripts enabled
-- @function [parent=#Debug] isMWScriptEnabled
-- @return #boolean
---
-- Reloads all Lua scripts
-- @function [parent=#Debug] reloadLua
--- ---
-- Navigation mesh rendering modes -- Navigation mesh rendering modes
-- @type NAV_MESH_RENDER_MODE -- @type NAV_MESH_RENDER_MODE

Loading…
Cancel
Save