diff --git a/src/modules/filesystem/physfs/Filesystem.cpp b/src/modules/filesystem/physfs/Filesystem.cpp index d510cb7c8..6e9a6e5ab 100644 --- a/src/modules/filesystem/physfs/Filesystem.cpp +++ b/src/modules/filesystem/physfs/Filesystem.cpp @@ -77,6 +77,7 @@ Filesystem::Filesystem() , fused(false) , fusedSet(false) { + requirePath = {"?.lua", "?/init.lua"}; } Filesystem::~Filesystem() @@ -671,6 +672,11 @@ bool Filesystem::isSymlink(const char *filename) const return PHYSFS_isSymbolicLink(filename) != 0; } +std::vector &Filesystem::getRequirePath() +{ + return requirePath; +} + } // physfs } // filesystem } // love diff --git a/src/modules/filesystem/physfs/Filesystem.h b/src/modules/filesystem/physfs/Filesystem.h index da3888fb1..ba4d9b810 100644 --- a/src/modules/filesystem/physfs/Filesystem.h +++ b/src/modules/filesystem/physfs/Filesystem.h @@ -26,6 +26,7 @@ #include #include #include +#include // LOVE #include "common/Module.h" @@ -262,6 +263,10 @@ public: **/ static int lines_i(lua_State *L); + // Require path accessors + // Not const because it's R/W + std::vector &getRequirePath(); + private: // Contains the current working directory (UTF8). @@ -290,6 +295,9 @@ private: bool fused; bool fusedSet; + // Search path for require + std::vector requirePath; + }; // Filesystem } // physfs diff --git a/src/modules/filesystem/wrap_Filesystem.cpp b/src/modules/filesystem/wrap_Filesystem.cpp index 22fd3fb14..ce241e11b 100644 --- a/src/modules/filesystem/wrap_Filesystem.cpp +++ b/src/modules/filesystem/wrap_Filesystem.cpp @@ -510,13 +510,11 @@ int w_isSymlink(lua_State *L) return 1; } -static std::vector requirePath = {"?.lua", "?/init.lua"}; - int w_getRequirePath(lua_State *L) { std::stringstream path; bool seperator = false; - for (auto &element : requirePath) + for (auto &element : instance()->getRequirePath()) { if (seperator) path << ";"; @@ -533,6 +531,7 @@ int w_getRequirePath(lua_State *L) int w_setRequirePath(lua_State *L) { std::string element = luax_checkstring(L, 1); + auto &requirePath = instance()->getRequirePath(); requirePath.clear(); std::stringstream path; @@ -555,7 +554,7 @@ int loader(lua_State *L) } auto *inst = instance(); - for (std::string element : requirePath) + for (std::string element : inst->getRequirePath()) { size_t pos = element.find('?'); if (pos == std::string::npos)