(Original) cocos2d-x 3.0 + Lua learning and working (4): common functions (6): merged tables: Table. Merge

Source: Internet
Author: User

The function here is mainly used to merge tables. Reference: quick_cocos.

Xingyue's contribution ~~~

-- [[-- Copy all keys and values in the source table to the target table object. If a key with the same name exists, the value of -- Example local tdest = {A = 1, B = 2} Local tsrc = {c = 3, D = 4} table. merge (tdest, tsrc) -- tdest = {A = 1, B = 2, c = 3, D = 4} -- @ Param tdest target table (T indicates table) -- @ Param tsrc source table (T indicates table) --] function table. merge (tdest, tsrc) for K, V in pairs (tsrc) Do tdest [k] = V endend

The table. Merge method is used to merge tables.
This method is very useful in online games. The attribute of a is changed, and the server returns a value. The stupid way is to list each element one by one and assign values one by one. However, with this method, you only need table. Merge once to overwrite the previous values and add new elements. It's very convenient ~~~ (TOM: Yes yes ...)

 

However, it should be noted that if the two tables have the same key but have different meanings, they cannot be covered at will and must be specially handled by everyone.

 

How many points do I have to think about, but it seems that there is nothing to say, the principle is easy to understand ~~~ (TOM: You have a chat ...)

 

The author uses cocos2d-x 3.0 + Lua learning and work experience, without the author's consent, please do not reprint! Thank you for your patience ~~~

This article is not approved by the author and cannot be reproduced. Otherwise, relevant responsibilities will be held accountable. For more information, see the source !!~~

Address: http://www.cnblogs.com/wodehao0808/p/4029494.html

(Original) cocos2d-x 3.0 + Lua learning and working (4): common functions (6): merged tables: Table. Merge

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.