Added some control params to dofiles lua method.
* File name contains string. * Recursive file checking for deep searches.
This commit is contained in:
parent
6c119627bb
commit
18d23653c4
|
@ -577,20 +577,19 @@ int LuaInterface::lua_dofile(lua_State* L)
|
||||||
|
|
||||||
int LuaInterface::lua_dofiles(lua_State* L)
|
int LuaInterface::lua_dofiles(lua_State* L)
|
||||||
{
|
{
|
||||||
std::string directory = g_lua.popString();
|
bool recursive = false;
|
||||||
|
if(g_lua.getTop() > 2) {
|
||||||
for(const std::string& fileName : g_resources.listDirectoryFiles(directory)) {
|
recursive = g_lua.popBoolean();
|
||||||
if(!g_resources.isFileType(fileName, "lua"))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1247,3 +1246,29 @@ int LuaInterface::getTop()
|
||||||
{
|
{
|
||||||
return lua_gettop(L);
|
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()); }
|
void clearStack() { pop(stackSize()); }
|
||||||
bool hasIndex(int index) { return (stackSize() >= (index < 0 ? -index : index) && index != 0); }
|
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
|
/// Pushes any type onto the stack
|
||||||
template<typename T, typename... Args>
|
template<typename T, typename... Args>
|
||||||
int polymorphicPush(const T& v, const Args&... args);
|
int polymorphicPush(const T& v, const Args&... args);
|
||||||
|
|
Loading…
Reference in New Issue