Created
January 10, 2019 10:25
-
-
Save Jerakin/0ff51c5cd96e4daf5d933eecf86bf74a to your computer and use it in GitHub Desktop.
Allows you to store urls centrally
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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