Kaynağa Gözat

Change handle() to avoid need for global table variable

Alois Mahdal 7 yıl önce
ebeveyn
işleme
360ebb9479
2 değiştirilmiş dosya ile 10 ekleme ve 12 silme
  1. 8
    8
      dotfiles/imapdomo/common.lua
  2. 2
    4
      dotfiles/imapdomo/main.lua

+ 8
- 8
dotfiles/imapdomo/common.lua Dosyayı Görüntüle

@@ -27,18 +27,18 @@ function file_exists(name)
27 27
     end
28 28
 end
29 29
 
30
-function init_host()
30
+function init_host(session)
31 31
     --
32 32
     -- Look for action handler in basepaths; do first one
33 33
     --
34
-    local init = imapdomo.dirs.host .. "/init.lua"
34
+    local init = session.dirs.host .. "/init.lua"
35 35
     if file_exists(init) then
36 36
         dofile(init)
37 37
         return
38 38
     end
39 39
 end
40 40
 
41
-function handle(action, basepaths)
41
+function handle(session)
42 42
     --
43 43
     -- Look for action handler in basepaths; do first one
44 44
     --
@@ -48,13 +48,13 @@ function handle(action, basepaths)
48 48
         cleanup = true,
49 49
         migrate = true
50 50
     }
51
-    if not valid[action] then
52
-        error("invalid action: " .. action)
51
+    if not valid[session.action] then
52
+        error("invalid action: " .. session.action)
53 53
         return nil
54 54
     end
55
-    init_host()
56
-    for k,v in ipairs({imapdomo.dirs.host, imapdomo.dirs.default}) do
57
-        attempt = v .. "/handlers/" .. action .. ".lua"
55
+    init_host(session)
56
+    for k,v in ipairs({session.dirs.host, session.dirs.default}) do
57
+        attempt = v .. "/handlers/" .. session.action .. ".lua"
58 58
         if file_exists(attempt) then
59 59
             dofile(attempt)
60 60
             return

+ 2
- 4
dotfiles/imapdomo/main.lua Dosyayı Görüntüle

@@ -1,13 +1,11 @@
1 1
 
2 2
 dofile ".imapdomo/common.lua"
3 3
 
4
-imapdomo = {
4
+handle({
5 5
     action = os.getenv("IMAPDOMO_ACTION"),
6 6
     dirs = {
7 7
         main = os.getenv("HOME") .. "/.imapdomo",
8 8
         host = os.getenv("HOME") .. "/.imapdomo/host/" .. shortname(),
9 9
         defhost = os.getenv("HOME") .. "/.imapdomo/default",
10 10
     }
11
-}
12
-
13
-handle(imapdomo.action)
11
+})