Mercurial Hosting > chat
diff src/lib/Utils.luan @ 4:2da10ece826f
add Chat
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 27 Oct 2024 20:39:18 -0600 |
parents | 2c63b10781e1 |
children | 7230c821c368 |
line wrap: on
line diff
--- a/src/lib/Utils.luan Thu Oct 24 21:43:44 2024 -0600 +++ b/src/lib/Utils.luan Sun Oct 27 20:39:18 2024 -0600 @@ -1,5 +1,8 @@ local Luan = require "luan:Luan.luan" local error = Luan.error +local type = Luan.type or error() +local ipairs = Luan.ipairs or error() +local set_metatable = Luan.set_metatable or error() local Http = require "luan:http/Http.luan" @@ -10,4 +13,39 @@ return request.scheme.."://"..request.headers["Host"] end +function Utils.to_list(input) + if input == nil then + return {} + elseif type(input) == "table" then + return input + else + return {input} + end +end + +local set_mt = {} +function set_mt.__index(table,key) + return false +end + +local function list_to_set(list) + local set = {} + for _, v in ipairs(list) do + set[v] = true + end + set_metatable(set,set_mt) + return set +end +Utils.list_to_set = list_to_set + +function Utils.to_set(obj) + if obj == nil then + return {} + elseif type(obj) == "table" then + return list_to_set(obj) + else + return {[obj]=true} + end +end + return Utils