Pop.Box/class.moon

39 lines
664 B
Plaintext
Raw Normal View History

--- @todo document this!
Class = (name, parent) ->
2017-08-14 12:48:36 +00:00
local newClass, base
base = {
__index: base
__class: newClass
}
newClass = setmetable {
__init: ->
__base: base
__name: name
}, {
__call: (cls, ...) ->
@ = setmetable({}, base)
cls.__init(@, ...)
return @
}
if parent
setmetable base, {
__parent: parent.__base
}
2017-08-14 12:48:36 +00:00
newClass.__parent = parent
newClass.__index = (cls, name) ->
val = rawget(base, name)
if val == nil
return parent[name]
else
return val
if parent.__inherited
parent\__inherited newClass
2017-08-14 12:48:36 +00:00
return newClass, base
return Class