scan.lua

changeset 7
038275cd92ed
parent 3
b2df1b3f2c83
child 26
77cd7b8fb6a6
--- a/scan.lua	Sun May 07 20:02:53 2017 +0100
+++ b/scan.lua	Tue Jan 16 16:39:48 2018 +0000
@@ -1,8 +1,9 @@
-
-module("scan", package.seeall)
 
-require('lfs')
-require('path')
+--@module scan
+local scan={}
+
+local lfs=require('lfs')
+local path=require('path')
 
 local function filtered_dir(d) 
     local f, s_, v_ = lfs.dir(d)
@@ -17,13 +18,13 @@
     return g, s_, v_
 end
 
-function scan(d)
+function scan.scan(d)
     local h={}
     for f in filtered_dir(d) do
         local n=d..'/'..f
         local a=lfs.attributes(n)
         if a.mode=='directory' then
-            local nh=scan(n)
+            local nh=scan.scan(n)
             h[f]=nh
         elseif a.mode=='file' then
             h[f]=true
@@ -32,17 +33,17 @@
     return h
 end
 
-function hfold(h, a, f, g)
+function scan.hfold(h, a, f, g)
     for n, c in pairs(h) do
         if type(c)=='table' then
-            hfold(c, f(a, n), f, g)
+            scan.hfold(c, f(a, n), f, g)
         else
             g(a, n)
         end
     end
 end
 
-function map(h, g, d)
+function scan.map(h, g, d)
     local function dir(prefix, name)
         local p=path.join(prefix, name)
         if d then
@@ -56,5 +57,7 @@
         g(f)
     end
     
-    hfold(h, "", dir, file)
+    scan.hfold(h, "", dir, file)
 end
+
+return scan

mercurial