Skip to content

Instantly share code, notes, and snippets.

@Jerakin
Created January 10, 2019 10:25
Show Gist options
  • Save Jerakin/0ff51c5cd96e4daf5d933eecf86bf74a to your computer and use it in GitHub Desktop.
Save Jerakin/0ff51c5cd96e4daf5d933eecf86bf74a to your computer and use it in GitHub Desktop.
Allows you to store urls centrally
-- Setting
-- url.set("MAIN", msg.url("."))
--
-- Shorthand set
-- url.MAIN = msg.url(".")
--
--
-- Getting
-- url.get("MAIN")
--
-- Shorthand get
-- url.MAIN
--
local M = {}
local urls = {}
local mt = {
__index = function (t,k)
if type(k) == "string" then
k = hash(k)
end
return urls[k]
end,
__newindex = function (t,k,v)
if type(k) == "string" then
k = hash(k)
end
urls[k] = v
end
}
function M.set(tag, url)
M[tag] = url
end
function M.get(tag)
return M[tag]
end
setmetatable(M, mt)
return M
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment