LUA Tool Classes

Source: Internet
Author: User

--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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.