--implementing Copy Object FunctionalityfunctionClone (object)Locallookup_table={} Local function _copy(object)if type(object) ~="Table" Then returnObjectElseIfLookup_table[object] Then returnLookup_table[object]End Localnew_table={} Lookup_table[object]=new_table forKey,valueinch Pairs(object) Donew_table[_copy(key)] =_copy(value)End returnSetmetable (new_table,getmetatable(object))End return _copy(object)End--generate a classfunctionclass (classname, Super)LocalSupertype =type(Super)--Type Returns a string that describes the type of the given value LocalCLSifSupertype ~="function" andSupertype ~="Table" Thensupertype=NilSuper=Nil End ifSupertype = ="function" or(Super andSuper.__ctype = =1) Then --inherited from native C + + ObjectCLS = {} ifSupertype = ="Table" Then --copy fields from super forKvinch Pairs(Super) DoCls[k] = VEndcls.__create=super.__create Cls.super=SuperElsecls.__create=SuperEndCls.ctor=function()EndCls.__cname=classname Cls.__ctype=1 functionCls.new (...)--constructor Function LocalInstance =cls.__create (...) --copy fields from class to native object forKvinch Pairs(CLS) DoInstance[k] = VEndInstance.class=cls Instance:ctor (...) Cls_add_instance (classname,instance)returninstanceEnd Else --inherited from Lua Object ifSuper ThenCLS=Clone (Super) Cls.super=SuperElseCLS= {ctor =function()End} EndCls.__cname=classname Cls.__ctype=2 --LuaCls.__index =CLSfunctioncls.new (...) LocalInstance =setmetatable({}, CLS) Instance.class=cls Instance:ctor (...) Cls_add_instance (classname,instance)returninstanceEnd End returnCLSEnd
LUA Tool Classes