class.lua 405 B

12345678910111213141516171819202122
  1. function class(parent)
  2. if not parent then parent = {} end
  3. local c = {}
  4. c.__index = c
  5. setmetatable(c, {
  6. __index = parent,
  7. __call = function (c, ...)
  8. local inst = setmetatable({}, c)
  9. if c.init == nil then
  10. parent.init(inst, ...)
  11. end
  12. inst:init(...)
  13. return inst
  14. end
  15. })
  16. return c
  17. end