Home > other >  O a lua code below application instance
O a lua code below application instance

Time:09-22

The function Class (base, _ator)
The local c={}
If not _ator and type (base)=='function' then
_ator=base
The base=nil
Elseif type (base)=='table' then
For I, v in pairs (base) do
[I]=c v
End
C. _base=base
End
The local mt={}
Mt. __call=function (classtb_1,... )
The local obj={}
Setmetatable (obj, c)
If _ator then
_ator (obj... )
End
Return obj
End
C. _ator=_ator
C.i s_a=function (self, klass)
The local m=getmetatable (self)
While m do
If m==klass then return true end
M=m. _base
End
Return false
End
Setmetatable (c, mt)
Return c
end

CodePudding user response:

This is to simulate oriented to something like programming

Local FaterClass=Class () - define a parent Class
Local ChildClass=Class (FaterClass) - define a subclass, inherited from the parent Class

Local childObj=ChildClass () - the new a subclass of like out

The face of like and Java, c + +,
  • Related