Skip to content

Commit

Permalink
move lua script check to place after mapping eop lua things
Browse files Browse the repository at this point in the history
  • Loading branch information
youneuoy committed Dec 12, 2024
1 parent c11a2dd commit 90e274f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
37 changes: 21 additions & 16 deletions M2TWEOP Code/M2TWEOP library/luaPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ int initLuaPlugin(bool isReload)
exit(0);
}
plugData::data.luaAll.addLegacy();
plugData::data.luaAll.checkLuaScript(luaFile);
plugData::data.luaAll.onPluginLoadF();

if (isReload) {
Expand All @@ -67,6 +68,26 @@ int initLuaPlugin(bool isReload)
return 1;
}

void luaPlugin::checkLuaScript(std::string& luaFilePath)
{
UINT defaultFlags = MB_ABORTRETRYIGNORE | MB_ICONEXCLAMATION; // Default type with exclamation icon
// This checks the syntax of the script, but does not execute it
sol::load_result fileRes = luaState.load_file(luaFilePath);
if (!fileRes.valid())
{
sol::error luaError = fileRes;
int result = MessageBoxA(nullptr, luaError.what(), "Lua syntax error!", defaultFlags);
console::handleMessageBoxResult(result);
return;
}
if (sol::protected_function_result result1 = fileRes(); !result1.valid())
{
sol::error luaError = result1;
int result = MessageBoxA(nullptr, luaError.what(), "Lua execution error!", defaultFlags);
console::handleMessageBoxResult(result);
return;
}
}
void reloadLua()
{
const std::string luaFile = globals::dataS.modPath + R"(\eopData\eopScripts\luaPluginScript.lua)";
Expand Down Expand Up @@ -180,22 +201,6 @@ sol::state* luaPlugin::init(std::string& luaFilePath, std::string& modPath)
return nullptr;
}

// This checks the syntax of the script, but does not execute it
sol::load_result fileRes = luaState.load_file(luaFilePath);
if (!fileRes.valid())
{
sol::error luaError = fileRes;
int result = MessageBoxA(nullptr, luaError.what(), "Lua syntax error!", defaultFlags);
console::handleMessageBoxResult(result);
return nullptr;
}
if (sol::protected_function_result result1 = fileRes(); !result1.valid())
{
sol::error luaError = result1;
int result = MessageBoxA(nullptr, luaError.what(), "Lua execution error!", defaultFlags);
console::handleMessageBoxResult(result);
return nullptr;
}

///M2TWEOP
//@section m2tweopTable
Expand Down
2 changes: 1 addition & 1 deletion M2TWEOP Code/M2TWEOP library/luaPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class luaPlugin

//lua functions and events controllers
void onPluginLoadF();

void checkLuaScript(std::string& luaFilePath);
sol::state luaState;
void fillHashMaps();
void fillHashMapsNonCampaign();
Expand Down

0 comments on commit 90e274f

Please sign in to comment.