Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wO={}
- wO.global={}
- wO.global.clone=function(self) local cloneObj={} for i,v in pairs(self) do cloneObj[i]=v end return cloneObj end
- wO.global.isA=function(self, arg)
- if self.className==arg then
- return true
- elseif self.className~="base" then
- if self.extends:isA(arg) then
- return true
- end
- else
- return false
- end
- end
- wO.global.className="base"
- wO.global.__settings={new=function(...) return {} end}
- wO.global.omt={}
- setmetatable(wO.global, {__tostring=function(a) return "Class "..a.className end})
- wO.classes={base=wO.global}
- local function newClass(a, ...)
- arg={...}
- b=(type(arg[1])=="table" and arg[1] or arg[2])
- b.extends=(type(arg[2])=="table" and wO.classes[arg[1]] or wO.classes["base"])
- b.className=a
- b.name=a.."Obj"
- local mt={}
- mt.__index=b.extends
- mt.__tostring=function(a) return "Class "..a.className end
- mt.__call=function(a,...) local arg={...} return newObj(a.className,...) end
- if not b.mt then
- b.mt=mt
- else
- for i,v in pairs(mt) do
- table.insert(b.mt)
- end
- end
- setmetatable(b, b.mt)
- wO.classes[a]=b
- end
- local function newObj(a,...)
- local o=(wO.classes[a].__settings.new(...))
- local omt={}
- for i,v in pairs(wO.classes[a].omt) do
- omt[i]=v
- end
- omt.__index=wO.classes[a]
- setmetatable(o, omt)
- return o
- end
- local function addClassInheritance(name, b)
- return function(...)
- newClass(name, b, arg[1])
- end
- end
- local function addClass(name)
- return function(...)
- local arg={...}
- if type(arg[1])=="table" then
- newClass(name,...)
- else
- return addClassInheritance(name,arg[1])
- end
- end
- end
- setmetatable(_G,{__index=function(_,a) return (a=="class" and addClass or (a==("newObj" or "new") and newObj or (wO.classes[a] or nil))) end}) --Ugly piece of code.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement