Browse Source

Change handle() to avoid need for global table variable

Alois Mahdal 8 years ago
parent
commit
360ebb9479
2 changed files with 10 additions and 12 deletions
  1. 8
    8
      dotfiles/imapdomo/common.lua
  2. 2
    4
      dotfiles/imapdomo/main.lua

+ 8
- 8
dotfiles/imapdomo/common.lua View File

27
     end
27
     end
28
 end
28
 end
29
 
29
 
30
-function init_host()
30
+function init_host(session)
31
     --
31
     --
32
     -- Look for action handler in basepaths; do first one
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
     if file_exists(init) then
35
     if file_exists(init) then
36
         dofile(init)
36
         dofile(init)
37
         return
37
         return
38
     end
38
     end
39
 end
39
 end
40
 
40
 
41
-function handle(action, basepaths)
41
+function handle(session)
42
     --
42
     --
43
     -- Look for action handler in basepaths; do first one
43
     -- Look for action handler in basepaths; do first one
44
     --
44
     --
48
         cleanup = true,
48
         cleanup = true,
49
         migrate = true
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
         return nil
53
         return nil
54
     end
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
         if file_exists(attempt) then
58
         if file_exists(attempt) then
59
             dofile(attempt)
59
             dofile(attempt)
60
             return
60
             return

+ 2
- 4
dotfiles/imapdomo/main.lua View File

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