summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Sluift/sluift.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/Sluift/sluift.cpp b/Sluift/sluift.cpp
index 2fd1e50..5e837c1 100644
--- a/Sluift/sluift.cpp
+++ b/Sluift/sluift.cpp
@@ -14,2 +14,3 @@
#include <boost/assign/list_of.hpp>
+#include <boost/filesystem.hpp>
@@ -253,2 +254,33 @@ SLUIFT_LUA_FUNCTION_WITH_HELP(
+/*******************************************************************************
+ * Filesystem Functions
+ ******************************************************************************/
+
+SLUIFT_LUA_FUNCTION(FS, list) {
+ boost::filesystem::path dir(std::string(Lua::checkString(L, 1)));
+ if (!boost::filesystem::exists(dir) || !boost::filesystem::is_directory(dir)) {
+ lua_pushnil(L);
+ lua_pushstring(L, "Argument is not an existing directory");
+ return 2;
+ }
+
+ boost::filesystem::directory_iterator i(dir);
+ std::vector<boost::filesystem::path> items(
+ i, boost::filesystem::directory_iterator());
+
+ lua_createtable(L, boost::numeric_cast<int>(items.size()), 0);
+ for (size_t i = 0; i < items.size(); ++i) {
+ lua_pushstring(L, items[i].string().c_str());
+ lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
+ }
+ Lua::registerTableToString(L, -1);
+ return 1;
+}
+
+SLUIFT_LUA_FUNCTION(FS, is_file) {
+ boost::filesystem::path file(std::string(Lua::checkString(L, 1)));
+ lua_pushboolean(L, boost::filesystem::is_regular_file(file));
+ return 1;
+}
+
@@ -412,2 +444,4 @@ SLUIFT_API int luaopen_sluift(lua_State* L) {
lua_setfield(L, -2, "crypto");
+ Lua::FunctionRegistry::getInstance().createFunctionTable(L, "FS");
+ lua_setfield(L, -2, "fs");
#ifdef HAVE_ITUNES