|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
--- Functions dealing with metatables and tables merging.
|
|
|
|
|
--- Tables and metatables general utility algorithms.
|
|
|
|
|
--
|
|
|
|
|
-- @module gear.meta
|
|
|
|
|
-- @copyright 2022 The DoubleFourteen Code Forge
|
|
|
|
@ -7,7 +7,11 @@
|
|
|
|
|
local meta = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--- Test whether 'obj' is an instance of a given class 'cls'.
|
|
|
|
|
--- Test whether 'obj' is an instance of the given class 'cls'.
|
|
|
|
|
--
|
|
|
|
|
-- @tparam table obj
|
|
|
|
|
-- @tparam table cls
|
|
|
|
|
-- @treturn bool
|
|
|
|
|
function meta.isinstance(obj, cls)
|
|
|
|
|
repeat
|
|
|
|
|
local m = getmetatable(obj)
|
|
|
|
@ -25,6 +29,10 @@ end
|
|
|
|
|
-- table 'to', whenever the same field is nil in that table.
|
|
|
|
|
--
|
|
|
|
|
-- The same process is applied recursively to sub-tables.
|
|
|
|
|
--
|
|
|
|
|
-- @tparam table to table to merge into
|
|
|
|
|
-- @tparam table from table to merge from
|
|
|
|
|
-- @treturn table destination table (a reference to 'to')
|
|
|
|
|
function meta.mergetable(to, from)
|
|
|
|
|
for k,v in pairs(from) do
|
|
|
|
|
if to[k] == nil then
|
|
|
|
|