@@ -244,6 +244,28 @@ namespace RTE {
244
244
}
245
245
}
246
246
247
+ // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
248
+
249
+ void LuaMan::SetLuaPath (const std::string &filePath) {
250
+ const std::string moduleName = g_PresetMan.GetModuleNameFromPath (filePath);
251
+ const std::string moduleFolder = g_PresetMan.IsModuleOfficial (moduleName) ? System::GetDataDirectory () : System::GetModDirectory ();
252
+ const std::string scriptPath = moduleFolder + moduleName + " /?.lua" ;
253
+
254
+ lua_getglobal (m_MasterState, " package" );
255
+ lua_getfield (m_MasterState, -1 , " path" ); // get field "path" from table at top of stack (-1).
256
+ std::string currentPath = lua_tostring (m_MasterState, -1 ); // grab path string from top of stack.
257
+
258
+ // check if scriptPath is already in there, if not add it.
259
+ if (currentPath.find (scriptPath) == std::string::npos) {
260
+ currentPath.append (" ;" + scriptPath);
261
+ }
262
+
263
+ lua_pop (m_MasterState, 1 ); // get rid of the string on the stack we just pushed previously.
264
+ lua_pushstring (m_MasterState, currentPath.c_str ()); // push the new one.
265
+ lua_setfield (m_MasterState, -2 , " path" ); // set the field "path" in table at -2 with value at top of stack.
266
+ lua_pop (m_MasterState, 1 ); // get rid of package table from top of stack.
267
+ }
268
+
247
269
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
248
270
249
271
int LuaMan::RunScriptFunctionString (const std::string &functionName, const std::string &selfObjectName, const std::vector<std::string_view> &variablesToSafetyCheck, const std::vector<const Entity *> &functionEntityArguments, const std::vector<std::string_view> &functionLiteralArguments) {
@@ -378,7 +400,7 @@ namespace RTE {
378
400
int error = 0 ;
379
401
380
402
lua_pushcfunction (m_MasterState, &AddFileAndLineToError);
381
- SetLuaPath (m_MasterState, fullScriptPath);
403
+ SetLuaPath (fullScriptPath);
382
404
// Load the script file's contents onto the stack and then execute it with pcall. Pcall will call the file and line error handler if there's an error by pointing 2 up the stack to it.
383
405
if (luaL_loadfile (m_MasterState, fullScriptPath.c_str ()) || lua_pcall (m_MasterState, 0 , LUA_MULTRET, -2 )) {
384
406
m_LastError = lua_tostring (m_MasterState, -1 );
@@ -395,27 +417,6 @@ namespace RTE {
395
417
return error;
396
418
}
397
419
398
- void LuaMan::SetLuaPath ( lua_State *luaState, const std::string &filePath )
399
- {
400
- const std::string moduleName = g_PresetMan.GetModuleNameFromPath ( filePath );
401
- const std::string moduleFolder = g_PresetMan.IsModuleOfficial (moduleName) ? " Data/" : System::GetModDirectory ();
402
- const std::string scriptPath = moduleFolder + moduleName + " /?.lua" ;
403
-
404
- lua_getglobal ( m_MasterState, " package" );
405
- lua_getfield ( m_MasterState, -1 , " path" ); // get field "path" from table at top of stack (-1)
406
- std::string cur_path = lua_tostring ( m_MasterState, -1 ); // grab path string from top of stack
407
-
408
- if (cur_path.find (scriptPath) == cur_path.npos ) { // check if scriptPath is already in there
409
- cur_path.append ( " ;" );
410
- cur_path.append ( scriptPath ); // if not add it
411
- }
412
-
413
- lua_pop ( m_MasterState, 1 ); // get rid of the string on the stack we just pushed previously
414
- lua_pushstring ( m_MasterState, cur_path.c_str () ); // push the new one
415
- lua_setfield ( m_MasterState, -2 , " path" ); // set the field "path" in table at -2 with value at top of stack
416
- lua_pop ( m_MasterState, 1 ); // get rid of package table from top of stack
417
- }
418
-
419
420
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
420
421
421
422
int LuaMan::RunScriptFileAndRetrieveFunctions (const std::string &filePath, const std::vector<std::string> &functionNamesToLookFor, std::unordered_map<std::string, LuabindObjectWrapper *> &outFunctionNamesAndObjects) {
0 commit comments