Mercurial Hosting > chat
view 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 source
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" local Utils = {} function Utils.base_url() local request = Http.request 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