LuaWeaver

Simple OO

Aug 9th, 2014
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.57 KB | None | 0 0
  1. local classes={
  2.     base={
  3.         className="base"
  4.     }
  5. }
  6.  
  7. local function addClass(name,base,tab)
  8.     tab.className=name
  9.     tab.super=base
  10.     classes[name]=setmetatable(tab,{
  11.         __index=base,
  12.         __call=function(self,...)
  13.             local new=setmetatable({},{__index=self})
  14.             if new.new then new:new(...) end
  15.             return new
  16.         end
  17.     })
  18.     return tab
  19. end
  20.  
  21. return {
  22.     class=function(name)
  23.         return function(arg1)
  24.             if type(arg1)=="string" then
  25.                 return function(arg2)
  26.                     return addClass(name,classes[arg1],arg2)
  27.                 end
  28.             end
  29.             return addClass(name,classes.base,arg1)
  30.         end
  31.     end
  32. }
Advertisement
Add Comment
Please, Sign In to add comment