Added some control params to dofiles lua method.

* File name contains string.
* Recursive file checking for deep searches.
master
BeniS 11 år sedan
förälder 6c119627bb
incheckning 18d23653c4

@ -577,20 +577,19 @@ int LuaInterface::lua_dofile(lua_State* L)
int LuaInterface::lua_dofiles(lua_State* L)
{
std::string directory = g_lua.popString();
for(const std::string& fileName : g_resources.listDirectoryFiles(directory)) {
if(!g_resources.isFileType(fileName, "lua"))
continue;
bool recursive = false;
if(g_lua.getTop() > 2) {
recursive = g_lua.popBoolean();
}
try {
g_lua.loadScript(directory + "/" + fileName);
g_lua.call(0, 0);
} catch(stdext::exception& e) {
g_lua.pushString(e.what());
g_lua.error();
}
std::string contains = "";
if(g_lua.getTop() > 1) {
contains = g_lua.popString();
}
std::string directory = g_lua.popString();
g_lua.loadFiles(directory, contains, recursive);
return 0;
}
@ -1247,3 +1246,29 @@ int LuaInterface::getTop()
{
return lua_gettop(L);
}
void LuaInterface::loadFiles(std::string directory, std::string contains, bool recursive)
{
for(const std::string& fileName : g_resources.listDirectoryFiles(directory)) {
std::string fullPath = directory + "/" + fileName;
if(recursive && g_resources.directoryExists(fullPath)) {
loadFiles(fullPath, contains, true);
continue;
}
if(!g_resources.isFileType(fileName, "lua"))
continue;
if(!contains.empty() && fileName.find(contains) == std::string::npos)
continue;
try {
g_lua.loadScript(fullPath);
g_lua.call(0, 0);
} catch(stdext::exception& e) {
g_lua.pushString(e.what());
g_lua.error();
}
}
}

@ -321,6 +321,8 @@ public:
void clearStack() { pop(stackSize()); }
bool hasIndex(int index) { return (stackSize() >= (index < 0 ? -index : index) && index != 0); }
void loadFiles(std::string directory, std::string contains, bool recursive = false);
/// Pushes any type onto the stack
template<typename T, typename... Args>
int polymorphicPush(const T& v, const Args&... args);

Laddar…
Avbryt
Spara