view src/lib/Utils.luan @ 39:df72d5d5d9dc

add cache_control
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 10 Aug 2025 06:25:35 +0900
parents d34d709a7a8e
children cc20eebaa74a
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local pairs = Luan.pairs or error()
local type = Luan.type 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.shallow_copy(t)
	local rtn = {}
	for key, val in pairs(t) do
		rtn[key] = val
	end
	return rtn
end

local function deep_copy2(v,map)
	if type(v) ~= "table" then
		return v
	end
	local v2 = map[v]
	if v2 ~= nil then
		return v2
	end
	local t = {}
	map[v] = t
	for key, val in pairs(v) do
		t[deep_copy2(key,map)] = deep_copy2(val,map)
	end
	return t
end

local function deep_copy(v)
	return deep_copy2(v,{})
end
Utils.deep_copy = deep_copy

--[[
function Utils.get_first(t)
	return pairs(t)()
end
]]

return Utils