From 74711c686f4e46144c37c79765ac05072967c87c Mon Sep 17 00:00:00 2001
From: Sergey Lyubka <valenok@gmail.com>
Date: Sat, 23 Nov 2013 13:58:27 +0000
Subject: [PATCH] Added directory scanning example, and enabled posix routines
 in Lua for unix environment

---
 build/lua_5.2.1.h       |  7 +++++--
 examples/lua/dirscan.lp | 15 +++++++++++++++
 2 files changed, 20 insertions(+), 2 deletions(-)
 create mode 100644 examples/lua/dirscan.lp

diff --git a/build/lua_5.2.1.h b/build/lua_5.2.1.h
index db012d787..2849a678d 100644
--- a/build/lua_5.2.1.h
+++ b/build/lua_5.2.1.h
@@ -18,6 +18,7 @@
 ** ===================================================================
 */
 
+#define LUA_COMPAT_ALL
 
 /*
 @@ LUA_ANSI controls the use of non-ansi features.
@@ -38,8 +39,6 @@
 #define LUA_USE_AFORMAT		/* assume 'printf' handles 'aA' specifiers */
 #endif
 
-
-
 #if defined(LUA_USE_LINUX)
 #define LUA_USE_POSIX
 #define LUA_USE_DLOPEN		/* needs an extra library: -ldl */
@@ -59,6 +58,10 @@
 #endif
 
 
+#if defined(__posix) || defined(__linux) || \
+  defined(__unix) || defined(__APPLE__)
+#define LUA_USE_POSIX
+#endif
 
 /*
 @@ LUA_USE_POSIX includes all functionality listed as X/Open System
diff --git a/examples/lua/dirscan.lp b/examples/lua/dirscan.lp
new file mode 100644
index 000000000..5525d2ce6
--- /dev/null
+++ b/examples/lua/dirscan.lp
@@ -0,0 +1,15 @@
+HTTP/1.0 200 OK
+Content-Type: text/plain
+
+<?
+  -- Directory scanning example
+
+  function scandir(dir)
+    local t = {}
+    for f in io.popen('dir ' .. dir):lines() do table.insert(t, f) end
+    return t
+  end
+
+  local tab = scandir('C:\\')
+  for k,v in pairs(tab) do mg.write(v, '\n') end
+?>
-- 
GitLab