3
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
4
|
3 local type = Luan.type or error()
|
|
4 local ipairs = Luan.ipairs or error()
|
|
5 local set_metatable = Luan.set_metatable or error()
|
3
|
6 local Http = require "luan:http/Http.luan"
|
|
7
|
|
8
|
|
9 local Utils = {}
|
|
10
|
|
11 function Utils.base_url()
|
|
12 local request = Http.request
|
|
13 return request.scheme.."://"..request.headers["Host"]
|
|
14 end
|
|
15
|
4
|
16 function Utils.to_list(input)
|
|
17 if input == nil then
|
|
18 return {}
|
|
19 elseif type(input) == "table" then
|
|
20 return input
|
|
21 else
|
|
22 return {input}
|
|
23 end
|
|
24 end
|
|
25
|
|
26 local set_mt = {}
|
|
27 function set_mt.__index(table,key)
|
|
28 return false
|
|
29 end
|
|
30
|
|
31 local function list_to_set(list)
|
|
32 local set = {}
|
|
33 for _, v in ipairs(list) do
|
|
34 set[v] = true
|
|
35 end
|
|
36 set_metatable(set,set_mt)
|
|
37 return set
|
|
38 end
|
|
39 Utils.list_to_set = list_to_set
|
|
40
|
|
41 function Utils.to_set(obj)
|
|
42 if obj == nil then
|
|
43 return {}
|
|
44 elseif type(obj) == "table" then
|
|
45 return list_to_set(obj)
|
|
46 else
|
|
47 return {[obj]=true}
|
|
48 end
|
|
49 end
|
|
50
|
3
|
51 return Utils
|