|
|
|
@ -9,16 +9,20 @@ local meta = {}
|
|
|
|
|
|
|
|
|
|
--- Test whether 'obj' is an instance of the given class 'cls'.
|
|
|
|
|
--
|
|
|
|
|
-- @tparam table obj
|
|
|
|
|
-- @tparam table cls
|
|
|
|
|
-- Note that nil is the only instance of the nil class.
|
|
|
|
|
--
|
|
|
|
|
-- @tparam table obj object instance to be tested
|
|
|
|
|
-- @tparam table cls class argument
|
|
|
|
|
-- @treturn bool
|
|
|
|
|
function meta.isinstance(obj, cls)
|
|
|
|
|
if rawequal(cls, nil) then return rawequal(obj, nil) end
|
|
|
|
|
|
|
|
|
|
repeat
|
|
|
|
|
local m = getmetatable(obj)
|
|
|
|
|
if rawequal(m, cls) then return true end
|
|
|
|
|
|
|
|
|
|
obj = m
|
|
|
|
|
until obj == nil
|
|
|
|
|
until rawequal(obj, nil)
|
|
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|