|
@@ -577,20 +577,19 @@ int LuaInterface::lua_dofile(lua_State* L)
|
577
|
577
|
|
578
|
578
|
int LuaInterface::lua_dofiles(lua_State* L)
|
579
|
579
|
{
|
580
|
|
- std::string directory = g_lua.popString();
|
581
|
|
-
|
582
|
|
- for(const std::string& fileName : g_resources.listDirectoryFiles(directory)) {
|
583
|
|
- if(!g_resources.isFileType(fileName, "lua"))
|
584
|
|
- continue;
|
|
580
|
+ bool recursive = false;
|
|
581
|
+ if(g_lua.getTop() > 2) {
|
|
582
|
+ recursive = g_lua.popBoolean();
|
|
583
|
+ }
|
585
|
584
|
|
586
|
|
- try {
|
587
|
|
- g_lua.loadScript(directory + "/" + fileName);
|
588
|
|
- g_lua.call(0, 0);
|
589
|
|
- } catch(stdext::exception& e) {
|
590
|
|
- g_lua.pushString(e.what());
|
591
|
|
- g_lua.error();
|
592
|
|
- }
|
|
585
|
+ std::string contains = "";
|
|
586
|
+ if(g_lua.getTop() > 1) {
|
|
587
|
+ contains = g_lua.popString();
|
593
|
588
|
}
|
|
589
|
+
|
|
590
|
+ std::string directory = g_lua.popString();
|
|
591
|
+ g_lua.loadFiles(directory, contains, recursive);
|
|
592
|
+
|
594
|
593
|
return 0;
|
595
|
594
|
}
|
596
|
595
|
|
|
@@ -1247,3 +1246,29 @@ int LuaInterface::getTop()
|
1247
|
1246
|
{
|
1248
|
1247
|
return lua_gettop(L);
|
1249
|
1248
|
}
|
|
1249
|
+
|
|
1250
|
+void LuaInterface::loadFiles(std::string directory, std::string contains, bool recursive)
|
|
1251
|
+{
|
|
1252
|
+ for(const std::string& fileName : g_resources.listDirectoryFiles(directory)) {
|
|
1253
|
+ std::string fullPath = directory + "/" + fileName;
|
|
1254
|
+
|
|
1255
|
+ if(recursive && g_resources.directoryExists(fullPath)) {
|
|
1256
|
+ loadFiles(fullPath, contains, true);
|
|
1257
|
+ continue;
|
|
1258
|
+ }
|
|
1259
|
+
|
|
1260
|
+ if(!g_resources.isFileType(fileName, "lua"))
|
|
1261
|
+ continue;
|
|
1262
|
+
|
|
1263
|
+ if(!contains.empty() && fileName.find(contains) == std::string::npos)
|
|
1264
|
+ continue;
|
|
1265
|
+
|
|
1266
|
+ try {
|
|
1267
|
+ g_lua.loadScript(fullPath);
|
|
1268
|
+ g_lua.call(0, 0);
|
|
1269
|
+ } catch(stdext::exception& e) {
|
|
1270
|
+ g_lua.pushString(e.what());
|
|
1271
|
+ g_lua.error();
|
|
1272
|
+ }
|
|
1273
|
+ }
|
|
1274
|
+}
|