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