From 48613441151c527c1e8ab46b4dcaa39f552f6326 Mon Sep 17 00:00:00 2001 From: CrosRoad95 Date: Fri, 2 Nov 2018 18:09:48 +0100 Subject: [PATCH 1/8] Improved warnings Previous looks like shit --- Client/mods/deathmatch/logic/lua/CLuaMain.cpp | 16 +++++--- Client/mods/deathmatch/logic/lua/CLuaMain.h | 8 ++-- Server/mods/deathmatch/logic/lua/CLuaMain.cpp | 21 ++++++----- Server/mods/deathmatch/logic/lua/CLuaMain.h | 10 ++--- .../deathmatch/logic/luadefs/CLuaUtilDefs.cpp | 11 +++++- Shared/sdk/SharedUtil.Misc.h | 2 + Shared/sdk/SharedUtil.Misc.hpp | 37 +++++++++++++++++++ 7 files changed, 79 insertions(+), 26 deletions(-) diff --git a/Client/mods/deathmatch/logic/lua/CLuaMain.cpp b/Client/mods/deathmatch/logic/lua/CLuaMain.cpp index 188f1a4f1d3..eb21ef60fb3 100644 --- a/Client/mods/deathmatch/logic/lua/CLuaMain.cpp +++ b/Client/mods/deathmatch/logic/lua/CLuaMain.cpp @@ -644,7 +644,7 @@ void CLuaMain::GetPackage(lua_State* L, SString& strName) // Load a Lua lib of a given name // /////////////////////////////////////////////////////////////// -bool CLuaMain::LoadLuaLib(lua_State* L, SString strName, SString& strError) +bool CLuaMain::LoadLuaLib(lua_State* L, SString strName, SString& strError, bool& bEmpty) { SString strPath = strName; // Name format shouldn't include slashes. Subdirs are dots. @@ -655,6 +655,8 @@ bool CLuaMain::LoadLuaLib(lua_State* L, SString strName, SString& strError) SString strResPath = m_pResource->GetResourceDirectoryPath(ACCESS_PUBLIC, ""); std::vector buffer; + + strError = "could not load module '" + strName + "'. Not found in locations:\n\t"; // Try /?.lua SString strFilePath = PathJoin(strResPath, strPath + ".lua"); if (FileExists(strFilePath)) @@ -662,7 +664,7 @@ bool CLuaMain::LoadLuaLib(lua_State* L, SString strName, SString& strError) else { // Don't use a format string for safety, so we construct the error by hand - strError += "error loading module " + strName + " from file " + strFilePath + ":\n\t The specified module could not be found"; + strError += "#1: " + ConformPath(strFilePath, "resources/") + "\n\t"; // Try /?/init.lua strFilePath = PathJoin(strResPath, strPath, "init.lua"); @@ -670,8 +672,7 @@ bool CLuaMain::LoadLuaLib(lua_State* L, SString strName, SString& strError) FileLoad(strFilePath, buffer); else { - strError += "\n"; - strError += "error loading module " + strName + " from file " + strFilePath + ":\n\t The specified module could not be found"; + strError += "#2: " + ConformPath(strFilePath, "resources/") + "\n\t"; return false; } } @@ -686,7 +687,7 @@ bool CLuaMain::LoadLuaLib(lua_State* L, SString strName, SString& strError) if (lua_type(L, -1) == LUA_TNIL) { - strError += "error loading module " + strName + " from file " + strFilePath + ":\n\t Module didn't return a value"; + strError += "#3: " + ConformPath(strFilePath, "resources/") + "\n\t"; return false; } @@ -694,7 +695,10 @@ bool CLuaMain::LoadLuaLib(lua_State* L, SString strName, SString& strError) return true; } else - strError += "error loading module " + strName + " from file " + strFilePath + ":\n\t Error loading script file"; + { + strError = "could not load module '" + strName + "' from file " + ConformPath(strFilePath, "resources/") + ": File is empty."; + bEmpty = true; + } return false; } diff --git a/Client/mods/deathmatch/logic/lua/CLuaMain.h b/Client/mods/deathmatch/logic/lua/CLuaMain.h index fa3be398e68..d2a77dd6745 100644 --- a/Client/mods/deathmatch/logic/lua/CLuaMain.h +++ b/Client/mods/deathmatch/logic/lua/CLuaMain.h @@ -78,10 +78,10 @@ class CLuaMain //: public CClient bool IsOOPEnabled(void) { return m_bEnableOOP; } - void InitPackageStorage(lua_State* L); // Create a psuedo package.loaded table - void GetPackage(lua_State* L, SString& strName); // Push the package value to the top of the stack - void SetPackage(lua_State* L, SString& strName); // Set the package to the value at the top of the stack - bool LoadLuaLib(lua_State* L, SString strName, SString& strError); // Load a lua library of a given name + void InitPackageStorage(lua_State* L); // Create a psuedo package.loaded table + void GetPackage(lua_State* L, SString& strName); // Push the package value to the top of the stack + void SetPackage(lua_State* L, SString& strName); // Set the package to the value at the top of the stack + bool LoadLuaLib(lua_State* L, SString strName, SString& strError, bool& bEmpty); // Load a lua library of a given name private: void InitSecurity(void); diff --git a/Server/mods/deathmatch/logic/lua/CLuaMain.cpp b/Server/mods/deathmatch/logic/lua/CLuaMain.cpp index 2c355d0400a..a67bca4b684 100644 --- a/Server/mods/deathmatch/logic/lua/CLuaMain.cpp +++ b/Server/mods/deathmatch/logic/lua/CLuaMain.cpp @@ -744,7 +744,7 @@ void CLuaMain::GetPackage(lua_State* L, SString& strName) // Load a Lua lib of a given name // /////////////////////////////////////////////////////////////// -bool CLuaMain::LoadLuaLib(lua_State* L, SString strName, SString& strError) +bool CLuaMain::LoadLuaLib(lua_State* L, SString strName, SString& strError, bool& bEmpty) { SString strPath = strName; // Name format shouldn't include slashes. Subdirs are dots. @@ -755,6 +755,7 @@ bool CLuaMain::LoadLuaLib(lua_State* L, SString strName, SString& strError) SString strResPath = m_pResource->IsResourceZip() ? m_pResource->GetResourceCacheDirectoryPath() : m_pResource->GetResourceDirectoryPath(); std::vector buffer; + strError = "could not load module '" + strName + "'. Not found in locations:\n\t"; // Try /?.lua SString strFilePath = PathJoin(strResPath, strPath + ".lua"); if (FileExists(strFilePath)) @@ -762,7 +763,7 @@ bool CLuaMain::LoadLuaLib(lua_State* L, SString strName, SString& strError) else { // Don't use a format string for safety, so we construct the error by hand - strError += "error loading module " + strName + " from file " + strFilePath + ":\n\t The specified module could not be found"; + strError += "#1: " + ConformPath(strFilePath, "resources/") + "\n\t"; // Try /?/init.lua strFilePath = PathJoin(strResPath, strPath, "init.lua"); @@ -770,8 +771,7 @@ bool CLuaMain::LoadLuaLib(lua_State* L, SString strName, SString& strError) FileLoad(strFilePath, buffer); else { - strError += "\n"; - strError += "error loading module " + strName + " from file " + strFilePath + ":\n\t The specified module could not be found"; + strError += "#2: " + ConformPath(strFilePath, "resources/") + "\n\t"; return false; } } @@ -786,7 +786,7 @@ bool CLuaMain::LoadLuaLib(lua_State* L, SString strName, SString& strError) if (lua_type(L, -1) == LUA_TNIL) { - strError += "error loading module " + strName + " from file " + strFilePath + ":\n\t Module didn't return a value"; + strError += "#3: " + ConformPath(strFilePath, "modules/") + "\n\t"; return false; } @@ -794,7 +794,10 @@ bool CLuaMain::LoadLuaLib(lua_State* L, SString strName, SString& strError) return true; } else - strError += "error loading module " + strName + " from file " + strFilePath + ":\n\t Error loading script file"; + { + strError = "could not load module '" + strName + "' from file " + ConformPath(strFilePath, "resources/") + ": File is empty."; + bEmpty = true; + } return false; } @@ -824,7 +827,7 @@ bool CLuaMain::LoadClib(lua_State* L, SString strName, SString& strError) if (!FileExists(strPath)) { - strError += "error loading module " + strName + " from file " + strPath + ":\n\t The specified module could not be found"; + strError += "#3: " + ConformPath(strPath,"modules/"); return false; } @@ -834,14 +837,14 @@ bool CLuaMain::LoadClib(lua_State* L, SString strName, SString& strError) !g_pGame->GetACLManager()->CanObjectUseRight(m_pResource->GetName().c_str(), CAccessControlListGroupObject::OBJECT_TYPE_RESOURCE, strName.c_str(), CAccessControlListRight::RIGHT_TYPE_MODULE, false)) { - strError += "error loading module " + strName + " from file " + strPath + ":\n\t ACL access denied. Grant \"module." + strName + + strError = "could not load module '" + strName + "' from file " + ConformPath(strPath, "modules/") + ":\n\t ACL access denied. Grant \"module." + strName + "\" right to resource " + m_pResource->GetName(); return false; } if (!luaL_loader_C(L, strName.c_str(), strPath.c_str()) || lua_type(L, -1) == LUA_TNIL) { - strError += "error loading module " + strName + " from file " + strPath + ":\n\t Failed to load module"; + strError = "failed to load module '" + strName + "' from file " + ConformPath(strPath, "modules/"); return false; } diff --git a/Server/mods/deathmatch/logic/lua/CLuaMain.h b/Server/mods/deathmatch/logic/lua/CLuaMain.h index 9e1572381dc..ecee7326dd5 100644 --- a/Server/mods/deathmatch/logic/lua/CLuaMain.h +++ b/Server/mods/deathmatch/logic/lua/CLuaMain.h @@ -108,11 +108,11 @@ class CLuaMain //: public CClient static int LuaLoadBuffer(lua_State* L, const char* buff, size_t sz, const char* name); static int OnUndump(const char* p, size_t n); - void InitPackageStorage(lua_State* L); // Create a psuedo package.loaded table - void GetPackage(lua_State* L, SString& strName); // Push the package value to the top of the stack - void SetPackage(lua_State* L, SString& strName); // Set the package to the value at the top of the stack - bool LoadLuaLib(lua_State* L, SString strName, SString& strError); // Load a lua library of a given name - bool LoadClib(lua_State* L, SString strName, SString& strError); // Load a C Lib of a given name + void InitPackageStorage(lua_State* L); // Create a psuedo package.loaded table + void GetPackage(lua_State* L, SString& strName); // Push the package value to the top of the stack + void SetPackage(lua_State* L, SString& strName); // Set the package to the value at the top of the stack + bool LoadLuaLib(lua_State* L, SString strName, SString& strError, bool& bEmpty); // Load a lua library of a given name + bool LoadClib(lua_State* L, SString strName, SString& strError); // Load a C Lib of a given name private: void InitSecurity(void); diff --git a/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp b/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp index fa34176a2e6..8bc321e2288 100644 --- a/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp +++ b/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp @@ -732,6 +732,7 @@ int CLuaUtilDefs::Require(lua_State* luaVM) if (!argStream.HasErrors()) { SString strError = ""; + bool bEmpty = false; // Check if package exists already, if so load it // stack: ["moduleName"] pLuaMain->GetPackage(luaVM, strMod); // stack: ["moduleName",pkgModule/nil] @@ -740,10 +741,16 @@ int CLuaUtilDefs::Require(lua_State* luaVM) lua_pop(luaVM, 1); // stack: ["moduleName"] // Check whether the appropriate pure lua module exists - if (pLuaMain->LoadLuaLib(luaVM, strMod, strError)) // stack: ["moduleName",pkgLuaMod/nil] + if (pLuaMain->LoadLuaLib(luaVM, strMod, strError, bEmpty)) // stack: ["moduleName",pkgLuaMod/nil] return 1; + + if (bEmpty) + { + m_pScriptDebugging->LogCustom(luaVM, strError); + lua_pushboolean(luaVM, false); + return 1; + } #ifndef MTA_CLIENT - strError += "\n"; // Check if a C library exists if (pLuaMain->LoadClib(luaVM, strMod, strError)) // stack: ["moduleName",fncModule/nil] return 1; diff --git a/Shared/sdk/SharedUtil.Misc.h b/Shared/sdk/SharedUtil.Misc.h index 669158d2e7b..3d849116817 100644 --- a/Shared/sdk/SharedUtil.Misc.h +++ b/Shared/sdk/SharedUtil.Misc.h @@ -209,6 +209,8 @@ namespace SharedUtil // SString ConformResourcePath(const char* szRes, bool bConvertToUnixPathSep = false); + SString ConformPath(const char* szRes, SString szPath, bool bConvertToUnixPathSep = false); + // // string stuff // diff --git a/Shared/sdk/SharedUtil.Misc.hpp b/Shared/sdk/SharedUtil.Misc.hpp index 845eff47f60..c997aa90e9b 100644 --- a/Shared/sdk/SharedUtil.Misc.hpp +++ b/Shared/sdk/SharedUtil.Misc.hpp @@ -1448,6 +1448,43 @@ SString SharedUtil::ConformResourcePath(const char* szRes, bool bConvertToUnixPa return strText; } +SString SharedUtil::ConformPath(const char* szRes, SString szPath, bool bConvertToUnixPathSep) +{ + SString strText = szRes ? szRes : ""; + char cPathSep; + + // Handle which path sep char +#ifdef WIN32 + if (!bConvertToUnixPathSep) + { + cPathSep = '\\'; + szPath = szPath.Replace("/", "\\"); + strText = strText.Replace("/", "\\"); + } + else +#endif + { + cPathSep = '/'; + szPath = szPath.Replace("\\", "/"); + strText = strText.Replace("\\", "/"); + } + + // Remove up to first occurrence + int iPos = strText.find(szPath); + if (iPos >= 0) + return SString("%s%s",szPath.c_str(), strText.substr(iPos + szPath.length()).c_str()); + + if (strText.substr(0, 3) == "...") + { + // Remove up to first '/' + int iPos = strText.find(cPathSep); + if (iPos >= 0) + return SString("%s%s",szPath.c_str(), strText.substr(iPos + 1).c_str()); + } + + return strText; +} + namespace SharedUtil { CArgMap::CArgMap(const SString& strArgSep, const SString& strPartsSep, const SString& strExtraDisallowedChars) From dfd5c828f86230d22bd45668da74e5a4685d5c69 Mon Sep 17 00:00:00 2001 From: CrosRoad95 Date: Fri, 2 Nov 2018 19:32:02 +0100 Subject: [PATCH 2/8] fix conflicts --- .../deathmatch/logic/lua/CLuaMain.Shared.cpp | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/Shared/mods/deathmatch/logic/lua/CLuaMain.Shared.cpp b/Shared/mods/deathmatch/logic/lua/CLuaMain.Shared.cpp index 1b292c051f5..023cd001b1d 100644 --- a/Shared/mods/deathmatch/logic/lua/CLuaMain.Shared.cpp +++ b/Shared/mods/deathmatch/logic/lua/CLuaMain.Shared.cpp @@ -1,10 +1,10 @@ /***************************************************************************** - * - * PROJECT: Multi Theft Auto - * LICENSE: See LICENSE in the top level directory - * FILE: Shared/mods/logic/lua/CLuaMain.Shared.cpp - * - *****************************************************************************/ +* +* PROJECT: Multi Theft Auto +* LICENSE: See LICENSE in the top level directory +* FILE: Shared/mods/logic/lua/CLuaMain.Shared.cpp +* +*****************************************************************************/ #include "StdInc.h" @@ -21,8 +21,8 @@ void CLuaMain::InitPackageStorage(lua_State* L) lua_pushstring(L, "loaded"); // stack: [tbl_new,"loaded"] lua_newtable(L); // stack: [tbl_new,"loaded",tbl_new2] - // We push our default Lua libs are loaded packages - std::vector szDefaultLibs = {"math", "string", "table", "debug", "utf8"}; + // We push our default Lua libs are loaded packages + std::vector szDefaultLibs = { "math", "string", "table", "debug", "utf8" }; for (auto it : szDefaultLibs) { lua_pushstring(L, it); // stack: [tbl_new,"loaded",tbl_new2,"math"] @@ -34,7 +34,7 @@ void CLuaMain::InitPackageStorage(lua_State* L) m_iPackageLoadedRef = luaL_ref(L, LUA_REGISTRYINDEX); // stack: [tbl_new,"loaded"] lua_rawgeti(L, LUA_REGISTRYINDEX, m_iPackageLoadedRef); // stack: [tbl_new,"loaded",tbl_new2] - // Finally, store our original table as global package.loaded + // Finally, store our original table as global package.loaded lua_settable(L, -3); // stack: [tbl_new] lua_setglobal(L, "package"); // stack: [] } @@ -61,7 +61,7 @@ void CLuaMain::SetPackage(lua_State* L, SString& strName) lua_pop(L, 2); // stack: [] lua_rawgeti(L, LUA_REGISTRYINDEX, iPkg); // stack: [varPkg] - // Cleanup our used registry entry, i.e. REGISTRY[i] = nil. + // Cleanup our used registry entry, i.e. REGISTRY[i] = nil. lua_pushnil(L); // stack: [varPkg,nil] lua_rawseti(L, LUA_REGISTRYINDEX, iPkg); // stack: [varPkg] } @@ -91,7 +91,7 @@ void CLuaMain::GetPackage(lua_State* L, SString& strName) // Load a Lua lib of a given name // /////////////////////////////////////////////////////////////// -bool CLuaMain::LoadLuaLib(lua_State* L, SString strName, SString& strError) +bool CLuaMain::LoadLuaLib(lua_State* L, SString strName, SString& strError, bool& bEmpty) { SString strPath = strName; // Name format shouldn't include slashes. Subdirs are dots. @@ -99,13 +99,14 @@ bool CLuaMain::LoadLuaLib(lua_State* L, SString strName, SString& strError) ReplaceOccurrencesInString(strPath, "/", ""); ReplaceOccurrencesInString(strPath, ".", "/"); -#ifdef MTA_CLIENT - SString strResPath = m_pResource->GetResourceDirectoryPath(ACCESS_PUBLIC, ""); -#else - SString strResPath = m_pResource->IsResourceZip() ? m_pResource->GetResourceCacheDirectoryPath() : m_pResource->GetResourceDirectoryPath(); -#endif + #ifdef MTA_CLIENT + SString strResPath = m_pResource->GetResourceDirectoryPath(ACCESS_PUBLIC, ""); + #else + SString strResPath = m_pResource->IsResourceZip() ? m_pResource->GetResourceCacheDirectoryPath() : m_pResource->GetResourceDirectoryPath(); + #endif std::vector buffer; + strError = "could not load module '" + strName + "'. Not found in locations:\n\t"; // Try /?.lua SString strFilePath = PathJoin(strResPath, strPath + ".lua"); if (FileExists(strFilePath)) @@ -113,7 +114,7 @@ bool CLuaMain::LoadLuaLib(lua_State* L, SString strName, SString& strError) else { // Don't use a format string for safety, so we construct the error by hand - strError += "error loading module " + strName + " from file " + strFilePath + ":\n\t The specified module could not be found"; + strError += "#1: " + ConformPath(strFilePath, "resources/") + "\n\t"; // Try /?/init.lua strFilePath = PathJoin(strResPath, strPath, "init.lua"); @@ -121,8 +122,7 @@ bool CLuaMain::LoadLuaLib(lua_State* L, SString strName, SString& strError) FileLoad(strFilePath, buffer); else { - strError += "\n"; - strError += "error loading module " + strName + " from file " + strFilePath + ":\n\t The specified module could not be found"; + strError += "#2: " + ConformPath(strFilePath, "resources/") + "\n\t"; return false; } } @@ -137,7 +137,7 @@ bool CLuaMain::LoadLuaLib(lua_State* L, SString strName, SString& strError) if (lua_type(L, -1) == LUA_TNIL) { - strError += "error loading module " + strName + " from file " + strFilePath + ":\n\t Module didn't return a value"; + strError += "#3: " + ConformPath(strFilePath, "modules/") + "\n\t"; return false; } @@ -145,7 +145,10 @@ bool CLuaMain::LoadLuaLib(lua_State* L, SString strName, SString& strError) return true; } else - strError += "error loading module " + strName + " from file " + strFilePath + ":\n\t Error loading script file"; + { + strError = "could not load module '" + strName + "' from file " + ConformPath(strFilePath, "resources/") + ": File is empty."; + bEmpty = true; + } return false; } From 13dd38a98478add5cdba3d7ab0963fccdd742ef4 Mon Sep 17 00:00:00 2001 From: CrosRoad95 Date: Fri, 2 Nov 2018 19:33:52 +0100 Subject: [PATCH 3/8] fix conflicts --- .../deathmatch/logic/lua/CLuaMain.Shared.cpp | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Shared/mods/deathmatch/logic/lua/CLuaMain.Shared.cpp b/Shared/mods/deathmatch/logic/lua/CLuaMain.Shared.cpp index 023cd001b1d..64f60fa4af9 100644 --- a/Shared/mods/deathmatch/logic/lua/CLuaMain.Shared.cpp +++ b/Shared/mods/deathmatch/logic/lua/CLuaMain.Shared.cpp @@ -1,10 +1,10 @@ /***************************************************************************** -* -* PROJECT: Multi Theft Auto -* LICENSE: See LICENSE in the top level directory -* FILE: Shared/mods/logic/lua/CLuaMain.Shared.cpp -* -*****************************************************************************/ + * + * PROJECT: Multi Theft Auto + * LICENSE: See LICENSE in the top level directory + * FILE: Shared/mods/logic/lua/CLuaMain.Shared.cpp + * + *****************************************************************************/ #include "StdInc.h" @@ -21,8 +21,8 @@ void CLuaMain::InitPackageStorage(lua_State* L) lua_pushstring(L, "loaded"); // stack: [tbl_new,"loaded"] lua_newtable(L); // stack: [tbl_new,"loaded",tbl_new2] - // We push our default Lua libs are loaded packages - std::vector szDefaultLibs = { "math", "string", "table", "debug", "utf8" }; + // We push our default Lua libs are loaded packages + std::vector szDefaultLibs = {"math", "string", "table", "debug", "utf8"}; for (auto it : szDefaultLibs) { lua_pushstring(L, it); // stack: [tbl_new,"loaded",tbl_new2,"math"] @@ -34,7 +34,7 @@ void CLuaMain::InitPackageStorage(lua_State* L) m_iPackageLoadedRef = luaL_ref(L, LUA_REGISTRYINDEX); // stack: [tbl_new,"loaded"] lua_rawgeti(L, LUA_REGISTRYINDEX, m_iPackageLoadedRef); // stack: [tbl_new,"loaded",tbl_new2] - // Finally, store our original table as global package.loaded + // Finally, store our original table as global package.loaded lua_settable(L, -3); // stack: [tbl_new] lua_setglobal(L, "package"); // stack: [] } @@ -61,7 +61,7 @@ void CLuaMain::SetPackage(lua_State* L, SString& strName) lua_pop(L, 2); // stack: [] lua_rawgeti(L, LUA_REGISTRYINDEX, iPkg); // stack: [varPkg] - // Cleanup our used registry entry, i.e. REGISTRY[i] = nil. + // Cleanup our used registry entry, i.e. REGISTRY[i] = nil. lua_pushnil(L); // stack: [varPkg,nil] lua_rawseti(L, LUA_REGISTRYINDEX, iPkg); // stack: [varPkg] } From cc651d5033e1360ffcc3df7d08704aace156cda8 Mon Sep 17 00:00:00 2001 From: Qais Patankar Date: Fri, 2 Nov 2018 23:52:10 +0000 Subject: [PATCH 4/8] Fix indentation --- Shared/mods/deathmatch/logic/lua/CLuaMain.Shared.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Shared/mods/deathmatch/logic/lua/CLuaMain.Shared.cpp b/Shared/mods/deathmatch/logic/lua/CLuaMain.Shared.cpp index 64f60fa4af9..0e5ab314383 100644 --- a/Shared/mods/deathmatch/logic/lua/CLuaMain.Shared.cpp +++ b/Shared/mods/deathmatch/logic/lua/CLuaMain.Shared.cpp @@ -99,11 +99,11 @@ bool CLuaMain::LoadLuaLib(lua_State* L, SString strName, SString& strError, bool ReplaceOccurrencesInString(strPath, "/", ""); ReplaceOccurrencesInString(strPath, ".", "/"); - #ifdef MTA_CLIENT - SString strResPath = m_pResource->GetResourceDirectoryPath(ACCESS_PUBLIC, ""); - #else - SString strResPath = m_pResource->IsResourceZip() ? m_pResource->GetResourceCacheDirectoryPath() : m_pResource->GetResourceDirectoryPath(); - #endif +#ifdef MTA_CLIENT + SString strResPath = m_pResource->GetResourceDirectoryPath(ACCESS_PUBLIC, ""); +#else + SString strResPath = m_pResource->IsResourceZip() ? m_pResource->GetResourceCacheDirectoryPath() : m_pResource->GetResourceDirectoryPath(); +#endif std::vector buffer; strError = "could not load module '" + strName + "'. Not found in locations:\n\t"; From 163fe45ba4b46656f01bfcd04e02b3b594c58c89 Mon Sep 17 00:00:00 2001 From: Qais Patankar Date: Sat, 3 Nov 2018 00:27:59 +0000 Subject: [PATCH 5/8] Tweak location text --- Shared/mods/deathmatch/logic/lua/CLuaMain.Shared.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Shared/mods/deathmatch/logic/lua/CLuaMain.Shared.cpp b/Shared/mods/deathmatch/logic/lua/CLuaMain.Shared.cpp index 0e5ab314383..7b6eeb79055 100644 --- a/Shared/mods/deathmatch/logic/lua/CLuaMain.Shared.cpp +++ b/Shared/mods/deathmatch/logic/lua/CLuaMain.Shared.cpp @@ -106,7 +106,7 @@ bool CLuaMain::LoadLuaLib(lua_State* L, SString strName, SString& strError, bool #endif std::vector buffer; - strError = "could not load module '" + strName + "'. Not found in locations:\n\t"; + strError = "error loading module '" + strName + "' from locations:\n\t"; // Try /?.lua SString strFilePath = PathJoin(strResPath, strPath + ".lua"); if (FileExists(strFilePath)) From 9812b45bf9f809e98343dffe5d02ee530f7daf04 Mon Sep 17 00:00:00 2001 From: Qais Patankar Date: Sat, 3 Nov 2018 00:30:30 +0000 Subject: [PATCH 6/8] fix path --- Shared/mods/deathmatch/logic/lua/CLuaMain.Shared.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Shared/mods/deathmatch/logic/lua/CLuaMain.Shared.cpp b/Shared/mods/deathmatch/logic/lua/CLuaMain.Shared.cpp index 7b6eeb79055..8aa23e6fc7e 100644 --- a/Shared/mods/deathmatch/logic/lua/CLuaMain.Shared.cpp +++ b/Shared/mods/deathmatch/logic/lua/CLuaMain.Shared.cpp @@ -137,7 +137,7 @@ bool CLuaMain::LoadLuaLib(lua_State* L, SString strName, SString& strError, bool if (lua_type(L, -1) == LUA_TNIL) { - strError += "#3: " + ConformPath(strFilePath, "modules/") + "\n\t"; + strError += "#3: " + ConformPath(strFilePath, "resources/") + "\n\t"; return false; } From e3d53a4ee648847f17f966e554f2e73549c1f3c1 Mon Sep 17 00:00:00 2001 From: CrosRoad95 Date: Sat, 3 Nov 2018 08:58:06 +0100 Subject: [PATCH 7/8] fixed `nil` return in require --- .../mods/deathmatch/logic/lua/CLuaMain.Shared.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Shared/mods/deathmatch/logic/lua/CLuaMain.Shared.cpp b/Shared/mods/deathmatch/logic/lua/CLuaMain.Shared.cpp index 64f60fa4af9..455d2a624ec 100644 --- a/Shared/mods/deathmatch/logic/lua/CLuaMain.Shared.cpp +++ b/Shared/mods/deathmatch/logic/lua/CLuaMain.Shared.cpp @@ -99,14 +99,14 @@ bool CLuaMain::LoadLuaLib(lua_State* L, SString strName, SString& strError, bool ReplaceOccurrencesInString(strPath, "/", ""); ReplaceOccurrencesInString(strPath, ".", "/"); - #ifdef MTA_CLIENT - SString strResPath = m_pResource->GetResourceDirectoryPath(ACCESS_PUBLIC, ""); - #else - SString strResPath = m_pResource->IsResourceZip() ? m_pResource->GetResourceCacheDirectoryPath() : m_pResource->GetResourceDirectoryPath(); - #endif +#ifdef MTA_CLIENT + SString strResPath = m_pResource->GetResourceDirectoryPath(ACCESS_PUBLIC, ""); +#else + SString strResPath = m_pResource->IsResourceZip() ? m_pResource->GetResourceCacheDirectoryPath() : m_pResource->GetResourceDirectoryPath(); +#endif std::vector buffer; - strError = "could not load module '" + strName + "'. Not found in locations:\n\t"; + strError = "error loading module '" + strName + "' from locations:\n\t"; // Try /?.lua SString strFilePath = PathJoin(strResPath, strPath + ".lua"); if (FileExists(strFilePath)) @@ -137,7 +137,8 @@ bool CLuaMain::LoadLuaLib(lua_State* L, SString strName, SString& strError, bool if (lua_type(L, -1) == LUA_TNIL) { - strError += "#3: " + ConformPath(strFilePath, "modules/") + "\n\t"; + strError = "module '" + strName + "' in location " + ConformPath(strFilePath, "resources/") + " didn't return a value."; + bEmpty = true; return false; } From 35f6183ae8cf3e835f3d1c0c023d45df7e9cdfd0 Mon Sep 17 00:00:00 2001 From: Patrik Juvonen Date: Wed, 20 Feb 2019 18:09:04 +0200 Subject: [PATCH 8/8] Fix code formatting --- Server/mods/deathmatch/logic/lua/CLuaMain.cpp | 6 +++--- Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp | 2 +- Shared/sdk/SharedUtil.Misc.hpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Server/mods/deathmatch/logic/lua/CLuaMain.cpp b/Server/mods/deathmatch/logic/lua/CLuaMain.cpp index f33e20a7a90..74539286e2a 100644 --- a/Server/mods/deathmatch/logic/lua/CLuaMain.cpp +++ b/Server/mods/deathmatch/logic/lua/CLuaMain.cpp @@ -686,7 +686,7 @@ bool CLuaMain::LoadClib(lua_State* L, SString strName, SString& strError) if (!FileExists(strPath)) { - strError += "#3: " + ConformPath(strPath,"modules/"); + strError += "#3: " + ConformPath(strPath, "modules/"); return false; } @@ -696,8 +696,8 @@ bool CLuaMain::LoadClib(lua_State* L, SString strName, SString& strError) !g_pGame->GetACLManager()->CanObjectUseRight(m_pResource->GetName().c_str(), CAccessControlListGroupObject::OBJECT_TYPE_RESOURCE, strName.c_str(), CAccessControlListRight::RIGHT_TYPE_MODULE, false)) { - strError = "could not load module '" + strName + "' from file " + ConformPath(strPath, "modules/") + ":\n\t ACL access denied. Grant \"module." + strName + - "\" right to resource " + m_pResource->GetName(); + strError = "could not load module '" + strName + "' from file " + ConformPath(strPath, "modules/") + ":\n\t ACL access denied. Grant \"module." + + strName + "\" right to resource " + m_pResource->GetName(); return false; } diff --git a/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp b/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp index f2a2629fcc1..c2d537eaacc 100644 --- a/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp +++ b/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp @@ -732,7 +732,7 @@ int CLuaUtilDefs::Require(lua_State* luaVM) if (!argStream.HasErrors()) { SString strError = ""; - bool bEmpty = false; + bool bEmpty = false; // Check if package exists already, if so load it // stack: ["moduleName"] pLuaMain->GetPackage(luaVM, strMod); // stack: ["moduleName",pkgModule/nil] diff --git a/Shared/sdk/SharedUtil.Misc.hpp b/Shared/sdk/SharedUtil.Misc.hpp index dfee528ca55..5b707775553 100644 --- a/Shared/sdk/SharedUtil.Misc.hpp +++ b/Shared/sdk/SharedUtil.Misc.hpp @@ -1472,14 +1472,14 @@ SString SharedUtil::ConformPath(const char* szRes, SString szPath, bool bConvert // Remove up to first occurrence int iPos = strText.find(szPath); if (iPos >= 0) - return SString("%s%s",szPath.c_str(), strText.substr(iPos + szPath.length()).c_str()); + return SString("%s%s", szPath.c_str(), strText.substr(iPos + szPath.length()).c_str()); if (strText.substr(0, 3) == "...") { // Remove up to first '/' int iPos = strText.find(cPathSep); if (iPos >= 0) - return SString("%s%s",szPath.c_str(), strText.substr(iPos + 1).c_str()); + return SString("%s%s", szPath.c_str(), strText.substr(iPos + 1).c_str()); } return strText;