summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/l_file.cc
diff options
context:
space:
mode:
authorDarshan Shaligram <dshaligram@users.sourceforge.net>2009-10-31 23:52:54 +0530
committerDarshan Shaligram <dshaligram@users.sourceforge.net>2009-11-01 00:12:43 +0530
commit67493d93236c231d9a16af420224769cf9daf6e9 (patch)
treef34eb9ffd0108aa5b67765c7a4db0a7298cfc30b /crawl-ref/source/l_file.cc
parent60ac7168be586603a6bb0afe6e1139cd63993a1d (diff)
downloadcrawl-ref-67493d93236c231d9a16af420224769cf9daf6e9.tar.gz
crawl-ref-67493d93236c231d9a16af420224769cf9daf6e9.zip
loadmaps.lua auto-loads .des files in dat.
Diffstat (limited to 'crawl-ref/source/l_file.cc')
-rw-r--r--crawl-ref/source/l_file.cc40
1 files changed, 33 insertions, 7 deletions
diff --git a/crawl-ref/source/l_file.cc b/crawl-ref/source/l_file.cc
index e619327cbe..bde31cb558 100644
--- a/crawl-ref/source/l_file.cc
+++ b/crawl-ref/source/l_file.cc
@@ -1,8 +1,10 @@
#include "AppHdr.h"
#include "clua.h"
+#include "cluautil.h"
#include "dlua.h"
#include "l_libs.h"
+#include "files.h"
#include "tags.h"
@@ -144,15 +146,39 @@ static int file_unmarshall_meta(lua_State *ls)
return (0);
}
+// Returns a Lua table of filenames in the named directory. The file names
+// returned are unqualified. The directory must be a relative path, and will
+// be resolved to an absolute path if necessary using datafile_path.
+LUAFN(_file_datadir_files)
+{
+ const std::string rawdir(luaL_checkstring(ls, 1));
+ // A filename suffix to match (such as ".des"). If empty, files
+ // will be unfiltered.
+ const std::string ext_filter(lua_isnoneornil(ls, 2) ? "" :
+ luaL_checkstring(ls, 2));
+ const std::string datadir(
+ datafile_path(rawdir, false, false, dir_exists));
+
+ if (datadir.empty())
+ luaL_error(ls, "Cannot find data directory: '%s'", rawdir.c_str());
+
+ const std::vector<std::string> files =
+ ext_filter.empty() ? get_dir_files(datadir) :
+ get_dir_files_ext(datadir, ext_filter);
+ return clua_stringtable(ls, files);
+}
+
static const struct luaL_reg file_dlib[] =
{
-{ "marshall", file_marshall },
-{ "marshall_meta", file_marshall_meta },
-{ "unmarshall_meta", file_unmarshall_meta },
-{ "unmarshall_number", file_unmarshall_number },
-{ "unmarshall_string", file_unmarshall_string },
-{ "unmarshall_fn", file_unmarshall_fn },
-{ NULL, NULL }
+ { "marshall", file_marshall },
+ { "marshall_meta", file_marshall_meta },
+ { "unmarshall_meta", file_unmarshall_meta },
+ { "unmarshall_number", file_unmarshall_number },
+ { "unmarshall_string", file_unmarshall_string },
+ { "unmarshall_fn", file_unmarshall_fn },
+
+ { "datadir_files", _file_datadir_files },
+ { NULL, NULL }
};
void dluaopen_file(lua_State *ls)