From 41a646f0387ad924953aad10c8c95e75cfecbf82 Mon Sep 17 00:00:00 2001 From: Yonaba Date: Tue, 27 Sep 2016 10:11:55 +0000 Subject: [PATCH] Fixes #28 --- 30log-clean.lua | 8 ++++++-- 30log-global.lua | 2 +- 30log.lua | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/30log-clean.lua b/30log-clean.lua index 5a91651..b6bf0fc 100644 --- a/30log-clean.lua +++ b/30log-clean.lua @@ -25,9 +25,13 @@ local function deep_copy(t, dest, aType) local r = dest or {} for k,v in pairs(t) do if aType ~= nil and type(v) == aType then - r[k] = (type(v) == 'table') and deep_copy(v) or v + r[k] = (type(v) == 'table') + and ((_classes[v] or _instances[v]) and v or deep_copy(v)) + or v elseif aType == nil then - r[k] = (type(v) == 'table') and k~= '__index' and deep_copy(v) or v + r[k] = (type(v) == 'table') + and k~= '__index' and ((_classes[v] or _instances[v]) and v or deep_copy(v)) + or v end end return r diff --git a/30log-global.lua b/30log-global.lua index 258436a..4ef5f25 100644 --- a/30log-global.lua +++ b/30log-global.lua @@ -1,7 +1,7 @@ local next, assert, pairs, type, tostring, setmetatable, baseMt, _instances, _classes, _class = next, assert, pairs, type, tostring, setmetatable, {}, setmetatable({},{__mode = 'k'}), setmetatable({},{__mode = 'k'}) local function assert_call_from_class(class, method) assert(_classes[class], ('Wrong method call. Expected class:%s.'):format(method)) end; local function assert_call_from_instance(instance, method) assert(_instances[instance], ('Wrong method call. Expected instance:%s.'):format(method)) end local default_filter = function() return true end -local function deep_copy(t, dest, aType) t = t or {}; local r = dest or {}; for k,v in pairs(t) do if aType ~= nil and type(v) == aType then r[k] = (type(v) == 'table') and deep_copy(v) or v elseif aType == nil then r[k] = (type(v) == 'table') and k~= '__index' and deep_copy(v) or v end; end return r end +local function deep_copy(t, dest, aType) t = t or {}; local r = dest or {}; for k,v in pairs(t) do if aType ~= nil and type(v) == aType then r[k] = (type(v) == 'table') and ((_classes[v] or _instances[v]) and v or deep_copy(v)) or v elseif aType == nil then r[k] = (type(v) == 'table') and k~= '__index' and ((_classes[v] or _instances[v]) and v or deep_copy(v)) or v end; end return r end local function instantiate(self,...) assert_call_from_class(self, 'new(...) or class(...)'); local instance = {class = self}; _instances[instance] = tostring(instance); deep_copy(self, instance, 'table') instance.__index, instance.__subclasses, instance.__instances, instance.mixins = nil, nil, nil, nil; setmetatable(instance,self); if self.init then if type(self.init) == 'table' then deep_copy(self.init, instance) else self.init(instance, ...) end end; return instance end diff --git a/30log.lua b/30log.lua index 44e245c..2dcb232 100644 --- a/30log.lua +++ b/30log.lua @@ -1,7 +1,7 @@ local next, assert, pairs, type, tostring, setmetatable, baseMt, _instances, _classes, _class = next, assert, pairs, type, tostring, setmetatable, {}, setmetatable({},{__mode = 'k'}), setmetatable({},{__mode = 'k'}) local function assert_call_from_class(class, method) assert(_classes[class], ('Wrong method call. Expected class:%s.'):format(method)) end; local function assert_call_from_instance(instance, method) assert(_instances[instance], ('Wrong method call. Expected instance:%s.'):format(method)) end local default_filter = function() return true end -local function deep_copy(t, dest, aType) t = t or {}; local r = dest or {}; for k,v in pairs(t) do if aType ~= nil and type(v) == aType then r[k] = (type(v) == 'table') and deep_copy(v) or v elseif aType == nil then r[k] = (type(v) == 'table') and k~= '__index' and deep_copy(v) or v end; end return r end +local function deep_copy(t, dest, aType) t = t or {}; local r = dest or {}; for k,v in pairs(t) do if aType ~= nil and type(v) == aType then r[k] = (type(v) == 'table') and ((_classes[v] or _instances[v]) and v or deep_copy(v)) or v elseif aType == nil then r[k] = (type(v) == 'table') and k~= '__index' and ((_classes[v] or _instances[v]) and v or deep_copy(v)) or v end; end return r end local function instantiate(self,...) assert_call_from_class(self, 'new(...) or class(...)'); local instance = {class = self}; _instances[instance] = tostring(instance); deep_copy(self, instance, 'table') instance.__index, instance.__subclasses, instance.__instances, instance.mixins = nil, nil, nil, nil; setmetatable(instance,self); if self.init then if type(self.init) == 'table' then deep_copy(self.init, instance) else self.init(instance, ...) end end; return instance end