summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/l_file.cc
diff options
context:
space:
mode:
authorDarshan Shaligram <dshaligram@users.sourceforge.net>2010-01-21 16:21:38 +0530
committerDarshan Shaligram <dshaligram@users.sourceforge.net>2010-01-21 16:31:59 +0530
commitbd71ccdb379a35f542a85011d92b913a4ef1b814 (patch)
tree85e9ea8882b1284ed793e5e90d6cf6070a6b2614 /crawl-ref/source/l_file.cc
parenta886ce98f29f256ac648c7469c4a1290922e1c91 (diff)
downloadcrawl-ref-bd71ccdb379a35f542a85011d92b913a4ef1b814.tar.gz
crawl-ref-bd71ccdb379a35f542a85011d92b913a4ef1b814.zip
Move .des files to dat/des, and allow them to be placed in subdirectories of dat/des.
Diffstat (limited to 'crawl-ref/source/l_file.cc')
-rw-r--r--crawl-ref/source/l_file.cc22
1 files changed, 22 insertions, 0 deletions
diff --git a/crawl-ref/source/l_file.cc b/crawl-ref/source/l_file.cc
index eee7e85701..b4b49b69e8 100644
--- a/crawl-ref/source/l_file.cc
+++ b/crawl-ref/source/l_file.cc
@@ -150,6 +150,27 @@ static int file_unmarshall_meta(lua_State *ls)
// 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_recursive)
+{
+ 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 =
+ get_dir_files_recursive(datadir, ext_filter);
+ return clua_stringtable(ls, files);
+}
+
+// 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));
@@ -196,6 +217,7 @@ static const struct luaL_reg file_dlib[] =
{ "unmarshall_fn", file_unmarshall_fn },
{ "writefile", _file_writefile },
{ "datadir_files", _file_datadir_files },
+ { "datadir_files_recursive", _file_datadir_files_recursive },
{ NULL, NULL }
};