mirror of
https://github.com/TangentFoxy/Pop.Box.git
synced 2024-12-15 12:44:20 +00:00
39 lines
664 B
Plaintext
39 lines
664 B
Plaintext
--- @todo document this!
|
|
Class = (name, parent) ->
|
|
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
|
|
}
|
|
|
|
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
|
|
|
|
return newClass, base
|
|
|
|
return Class
|