Pop.Box/util.moon

31 lines
820 B
Plaintext
Raw Normal View History

2016-06-21 05:52:44 +00:00
--- Utility functions, intended for internal use only.
--- @module util
--- @copyright Paul Liverman III (2015-2016)
--- @license The MIT License (MIT)
--- @function inheritsFromElement
2016-08-21 07:49:16 +00:00
--- @tparam table object MoonScript object to be checked for inheritence from
--- the "element" element.
--- @treturn boolean Is the table an object inherting from "element"?
--- @raise Can error if the table has a similar structure to a MoonScript object
--- without being the same structure.
--- @see Element
2016-06-21 05:52:44 +00:00
inheritsFromElement = (object) ->
2017-08-28 08:49:12 +00:00
if object and type(object) == "table" and object.__class
cls = object.__class
2016-06-21 05:52:44 +00:00
2017-08-28 08:49:12 +00:00
if cls.__name == "element"
return true
2016-06-21 05:52:44 +00:00
2017-08-28 08:49:12 +00:00
while cls.__parent
cls = cls.__parent
if cls.__name == "element"
return true
2016-06-21 05:52:44 +00:00
2017-08-28 08:49:12 +00:00
return false
2016-06-21 05:52:44 +00:00
return {
2017-08-28 08:49:12 +00:00
:inheritsFromElement
2016-06-21 05:52:44 +00:00
}