comparison src/lib/Shared.luan @ 13:24668255cede

preprocess urls
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 03 Jul 2022 23:59:41 -0600
parents 0472897e790d
children 3ea49246d6a7
comparison
equal deleted inserted replaced
12:ad1604c72156 13:24668255cede
1 local Luan = require "luan:Luan.luan" 1 local Luan = require "luan:Luan.luan"
2 local error = Luan.error 2 local error = Luan.error
3 local ipairs = Luan.ipairs or error()
4 local set_metatable = Luan.set_metatable or error()
3 local Http = require "luan:http/Http.luan" 5 local Http = require "luan:http/Http.luan"
4 local Io = require "luan:Io.luan" 6 local Io = require "luan:Io.luan"
5 local uri = Io.uri or error() 7 local uri = Io.uri or error()
6 local Parsers = require "luan:Parsers.luan" 8 local Parsers = require "luan:Parsers.luan"
7 local json_parse = Parsers.json_parse or error() 9 local json_parse = Parsers.json_parse or error()
67 } 69 }
68 local response = uri(url,options).read_text() 70 local response = uri(url,options).read_text()
69 return json_parse(response) 71 return json_parse(response)
70 end 72 end
71 73
74 local set_mt = {}
75 function set_mt.__index(table,key)
76 return false
77 end
78
79 function Shared.list_to_set(list)
80 local set = {}
81 for _, v in ipairs(list) do
82 set[v] = true
83 end
84 set_metatable(set,set_mt)
85 return set
86 end
87
72 return Shared 88 return Shared