Module:Utilities: Difference between revisionsGive feedback
m url_encode returns '' early |
m deep_copy init |
||
| Line 71: | Line 71: | ||
end | end | ||
--Much room for expansion here | --Much room for expansion here, currently just replaces spaces with underscores essentially | ||
--so that it can be used in a url directly | |||
p.url_encode = function(str) | p.url_encode = function(str) | ||
if type(str) == 'table' and str.args then | if type(str) == 'table' and str.args then | ||
| Line 84: | Line 85: | ||
return result --must assign as local result first to grab just first returned result | return result --must assign as local result first to grab just first returned result | ||
end | end | ||
--Creates a deepCopy of a table | |||
local function deep_copy(orig) | |||
local orig_type = type(orig) | |||
local copy | |||
if orig_type == "table" then | |||
copy = {} | |||
for key, value in pairs(orig) do | |||
copy[deep_copy(key)] = deep_copy(value) | |||
end | |||
setmetatable(copy, deepCopy(getmetatable(orig))) | |||
else -- For non-table types, simply return the original value | |||
copy = orig | |||
end | |||
return copy | |||
end | |||
return p | return p | ||