Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 2ceeb60

Browse files
committed
Fix issues with HasScript, AddScript, EnableScript and DisableScript if you don't qualify your filepath
1 parent 8ea46f5 commit 2ceeb60

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

Lua/LuaAdapterDefinitions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ namespace RTE {
333333

334334
#pragma region MovableObject Lua Adapters
335335
struct LuaAdaptersMovableObject {
336+
static bool HasScript(MovableObject *luaSelfObject, const std::string &scriptPath);
336337
static bool AddScript(MovableObject *luaSelfObject, const std::string &scriptPath);
337338
static bool EnableScript(MovableObject *luaSelfObject, const std::string &scriptPath);
338339
static bool DisableScript(MovableObject *luaSelfObject, const std::string &scriptPath);

Lua/LuaAdapters.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -298,26 +298,32 @@ namespace RTE {
298298
return luaSelfObject->GetTotalValue(nativeModule, foreignMult, 1.0F);
299299
}
300300

301+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
302+
303+
bool LuaAdaptersMovableObject::HasScript(MovableObject *luaSelfObject, const std::string &scriptPath) {
304+
return luaSelfObject->HasScript(g_PresetMan.GetFullModulePath(scriptPath));
305+
}
306+
301307
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
302308

303309
bool LuaAdaptersMovableObject::AddScript(MovableObject *luaSelfObject, const std::string &scriptPath) {
304-
switch (luaSelfObject->LoadScript(luaSelfObject->CorrectBackslashesInPath(scriptPath))) {
310+
switch (std::string correctedScriptPath = g_PresetMan.GetFullModulePath(scriptPath); luaSelfObject->LoadScript(luaSelfObject->CorrectBackslashesInPath(correctedScriptPath))) {
305311
case 0:
306312
return true;
307313
case -1:
308-
g_ConsoleMan.PrintString("ERROR: The script path " + scriptPath + " was empty.");
314+
g_ConsoleMan.PrintString("ERROR: The script path " + correctedScriptPath + " was empty.");
309315
break;
310316
case -2:
311-
g_ConsoleMan.PrintString("ERROR: The script path " + scriptPath + " did not point to a valid file.");
317+
g_ConsoleMan.PrintString("ERROR: The script path " + correctedScriptPath + " did not point to a valid file.");
312318
break;
313319
case -3:
314-
g_ConsoleMan.PrintString("ERROR: The script path " + scriptPath + " is already loaded onto this object.");
320+
g_ConsoleMan.PrintString("ERROR: The script path " + correctedScriptPath + " is already loaded onto this object.");
315321
break;
316322
case -4:
317-
g_ConsoleMan.PrintString("ERROR: Failed to do necessary setup to add scripts while attempting to add the script with path " + scriptPath + ". This has nothing to do with your script, please report it to a developer.");
323+
g_ConsoleMan.PrintString("ERROR: Failed to do necessary setup to add scripts while attempting to add the script with path " + correctedScriptPath + ". This has nothing to do with your script, please report it to a developer.");
318324
break;
319325
case -5:
320-
g_ConsoleMan.PrintString("ERROR: The file with script path " + scriptPath + " could not be run. Please check that this is a valid Lua file.");
326+
g_ConsoleMan.PrintString("ERROR: The file with script path " + correctedScriptPath + " could not be run. Please check that this is a valid Lua file.");
321327
break;
322328
default:
323329
RTEAbort("Reached default case while adding script. This should never happen!");
@@ -329,13 +335,13 @@ namespace RTE {
329335
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
330336

331337
bool LuaAdaptersMovableObject::EnableScript(MovableObject *luaSelfObject, const std::string &scriptPath) {
332-
return luaSelfObject->EnableOrDisableScript(scriptPath, true);
338+
return luaSelfObject->EnableOrDisableScript(g_PresetMan.GetFullModulePath(scriptPath), true);
333339
}
334340

335341
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
336342

337343
bool LuaAdaptersMovableObject::DisableScript(MovableObject *luaSelfObject, const std::string &scriptPath) {
338-
return luaSelfObject->EnableOrDisableScript(scriptPath, false);
344+
return luaSelfObject->EnableOrDisableScript(g_PresetMan.GetFullModulePath(scriptPath), false);
339345
}
340346

341347
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Lua/LuaBindingsEntities.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ namespace RTE {
10201020
.def("GetRootParent", (MovableObject * (MovableObject::*)())&MovableObject::GetRootParent)
10211021
.def("GetRootParent", (const MovableObject * (MovableObject::*)() const)&MovableObject::GetRootParent)
10221022
.def("ReloadScripts", &MovableObject::ReloadScripts)
1023-
.def("HasScript", &MovableObject::HasScript)
1023+
.def("HasScript", &LuaAdaptersMovableObject::HasScript)
10241024
.def("AddScript", &LuaAdaptersMovableObject::AddScript)
10251025
.def("ScriptEnabled", &MovableObject::ScriptEnabled)
10261026
.def("EnableScript", &LuaAdaptersMovableObject::EnableScript)

0 commit comments

Comments
 (0)