-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
39 lines (37 loc) · 732 Bytes
/
init.lua
File metadata and controls
39 lines (37 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
local function default() end
local function switch(var)
-- TODO: Can we avoid recreating new function each time?
return function (map)
for case, value in pairs(map) do
local matches = false
if type(case) == "table" then
for _, v in pairs(case) do
if v == var then
matches = true
break
end
end
else
matches = var == case
end
if matches then
if type(value) == "function" then
return value()
else
return value
end
end
end
if map[default] then
local defaultvalue = map[default]
if type(defaultvalue) == "function" then
return defaultvalue()
else
return defaultvalue
end
end
end
end
return function ()
return switch, default
end