4,951
edits
Falterfire (talk | contribs) (Copied over some handy shared functions I'll probably need later.) |
Falterfire (talk | contribs) No edit summary |
||
Line 234: | Line 234: | ||
end | end | ||
-- copies the contents of a variable; for | -- copies the contents of a variable; handy for when you might want to modify an object taken from a data file | ||
-- | -- or any other read-only variable | ||
-- Stolen from https://gist.github.com/tylerneylon/81333721109155b2d244 | |||
function p.clone(orig) | |||
if type(obj) ~= 'table' then return obj end | |||
local res = {} | |||
function p. | for k, v in pairs(obj) do res[clone(k)] = clone(v) end | ||
return res | |||
return | |||
end | end | ||
return p | return p |