Skip to content

Commit 1827c71

Browse files
committed
little more work for lua debugging
1 parent 73fca54 commit 1827c71

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

Data/Base.rte/AI/SharedBehaviors.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,8 @@ function SharedBehaviors.GoToWpt(AI, Owner, Abort)
438438
local NeedsNewPath, Waypoint, HasMovePath, Dist, CurrDist;
439439
NeedsNewPath = true;
440440

441+
require("mobdebug").start()
442+
441443
Owner:RemoveNumberValue("AI_StuckForTime");
442444

443445
while true do

Source/Managers/LuaMan.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,12 @@ void LuaStateWrapper::Initialize() {
272272
"_AsyncPathCallbacks = {};\n"
273273
"_AddAsyncPathCallback = function(id, callback) _AsyncPathCallbacks[id] = callback; end\n"
274274
"_TriggerAsyncPathCallback = function(id, param) if _AsyncPathCallbacks[id] ~= nil then _AsyncPathCallbacks[id](param); _AsyncPathCallbacks[id] = nil; end end\n");
275+
276+
if (g_SettingsMan.EnableLuaDebugging()) {
277+
// Enable Lua debugging
278+
// Right now we're not requiring the mobdebug module because it doesn't play well with multithreading- we need this to additionally push everything into one Lua state.
279+
luaL_dostring(m_State, "require(\"mobdebug\").coro(); --require(\"mobdebug\").start();");
280+
}
275281
}
276282

277283
void LuaStateWrapper::Destroy() {

Source/Managers/SettingsMan.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ void SettingsMan::Clear() {
4242
m_ShowMetaScenes = false;
4343

4444
m_DisableLuaJIT = false;
45+
m_EnableLuaDebugging = false;
4546
m_RecommendedMOIDCount = 512;
4647
m_SceneBackgroundAutoScaleMode = 1;
4748
m_DisableFactionBuyMenuThemes = false;
@@ -158,6 +159,7 @@ int SettingsMan::ReadProperty(const std::string_view& propName, Reader& reader)
158159
MatchProperty("DefaultActivityName", { reader >> g_ActivityMan.m_DefaultActivityName; });
159160
MatchProperty("DefaultSceneName", { reader >> g_SceneMan.m_DefaultSceneName; });
160161
MatchProperty("DisableLuaJIT", { reader >> m_DisableLuaJIT; });
162+
MatchProperty("EnableLuaDebugging", { reader >> m_EnableLuaDebugging; });
161163
MatchProperty("RecommendedMOIDCount", { reader >> m_RecommendedMOIDCount; });
162164
MatchProperty("SceneBackgroundAutoScaleMode", { SetSceneBackgroundAutoScaleMode(std::stoi(reader.ReadPropValue())); });
163165
MatchProperty("DisableFactionBuyMenuThemes", { reader >> m_DisableFactionBuyMenuThemes; });
@@ -284,6 +286,7 @@ int SettingsMan::Save(Writer& writer) const {
284286
writer.NewLineString("// Engine Settings", false);
285287
writer.NewLine(false);
286288
writer.NewPropertyWithValue("DisableLuaJIT", m_DisableLuaJIT);
289+
writer.NewPropertyWithValue("EnableLuaDebugging", m_EnableLuaDebugging);
287290
writer.NewPropertyWithValue("RecommendedMOIDCount", m_RecommendedMOIDCount);
288291
writer.NewPropertyWithValue("SceneBackgroundAutoScaleMode", m_SceneBackgroundAutoScaleMode);
289292
writer.NewPropertyWithValue("DisableFactionBuyMenuThemes", m_DisableFactionBuyMenuThemes);

Source/Managers/SettingsMan.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ namespace RTE {
4949
/// @return Whether LuaJIT is disabled or not.
5050
bool DisableLuaJIT() const { return m_DisableLuaJIT; }
5151

52+
/// Returns whether Lua debugging is disabled or not.
53+
/// @return Whether Lua debugging is disabled or not.
54+
bool EnableLuaDebugging() const { return m_EnableLuaDebugging; }
55+
5256
/// Returns the recommended MOID count. If this amount is exceeded then some units may be removed at the start of the activity.
5357
/// @return Recommended MOID count.
5458
int RecommendedMOIDCount() const { return m_RecommendedMOIDCount; }
@@ -385,6 +389,7 @@ namespace RTE {
385389
bool m_ShowMetaScenes; //!< Show MetaScenes in editors and activities.
386390

387391
bool m_DisableLuaJIT; //!< Whether to disable LuaJIT or not. Disabling will skip loading the JIT library entirely as just setting 'jit.off()' seems to have no visible effect.
392+
bool m_EnableLuaDebugging; //!< Whether the Lua debugger mode is enabled or not. This will disable JITing and will attempt to connect to a debugger on launch.
388393
int m_RecommendedMOIDCount; //!< Recommended max MOID's before removing actors from scenes.
389394
int m_SceneBackgroundAutoScaleMode; //!< Scene background layer auto-scaling mode. 0 for off, 1 for fit screen dimensions and 2 for always upscaled to x2.
390395
bool m_DisableFactionBuyMenuThemes; //!< Whether faction BuyMenu theme support is disabled.

0 commit comments

Comments
 (0)