Fix util.deep_copy

This commit is contained in:
Thomas Goyne 2013-05-04 17:03:25 -07:00
parent d9ad794dcb
commit 5dd982b742

View file

@ -14,6 +14,7 @@
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
sformat = string.format sformat = string.format
local *
-- Make a shallow copy of a table -- Make a shallow copy of a table
copy = (tbl) -> {k, v for k, v in pairs tbl} copy = (tbl) -> {k, v for k, v in pairs tbl}
@ -23,9 +24,9 @@ copy = (tbl) -> {k, v for k, v in pairs tbl}
deep_copy = (tbl) -> deep_copy = (tbl) ->
seen = {} seen = {}
copy = (val) -> copy = (val) ->
return val if type(tbl) != 'table' return val if type(val) != 'table'
return seen[val] if seen[tbl] return seen[val] if seen[val]
seen[val] = tbl seen[val] = val
{k, copy(v) for k, v in pairs val} {k, copy(v) for k, v in pairs val}
copy tbl copy tbl
@ -74,7 +75,7 @@ HSV_to_RGB = (H, S, V) ->
-- Saturation is zero, make grey -- Saturation is zero, make grey
if S == 0 if S == 0
r = @clamp(V*255, 0, 255) r = clamp(V*255, 0, 255)
g = r g = r
b = r b = r