From 079c1d0e18ed52056fc23d1a4b8be3d25c7e601e Mon Sep 17 00:00:00 2001 From: Pablo Ariel Mayobre Date: Sat, 14 Mar 2020 18:45:15 -0300 Subject: [PATCH] Utils.shallowCopy as a default serializer/deserializer for Components --- concord/component.lua | 3 +++ concord/utils.lua | 2 ++ 2 files changed, 5 insertions(+) diff --git a/concord/component.lua b/concord/component.lua index 0ac83e6..04691a6 100644 --- a/concord/component.lua +++ b/concord/component.lua @@ -4,6 +4,7 @@ local PATH = (...):gsub('%.[^%.]+$', '') local Components = require(PATH..".components") +local Utils = require(PATH..".utils") local Component = {} Component.__mt = { @@ -47,9 +48,11 @@ function Component:__populate() -- luacheck: ignore end function Component:serialize() -- luacheck: ignore + return Utils.shallowCopy(self, {}) end function Component:deserialize(data) -- luacheck: ignore + Utils.shallowCopy(data, self) end -- Internal: Creates a new Component. diff --git a/concord/utils.lua b/concord/utils.lua index 68ae22b..da83c4d 100644 --- a/concord/utils.lua +++ b/concord/utils.lua @@ -10,6 +10,8 @@ function Utils.shallowCopy(orig, target) for key, value in pairs(orig) do target[key] = value end + + return target end --- Requires files and puts them in a table.