Cocos2d-x scripting language LUA basic data structure-tables (table)

Source: Internet
Author: User
Tags lua

cocos2d-x scripting language LUA basic data structure-tables (table)
Tableis aLuathe only data structure in the. Data structures provided by other languages, such as:Arrays,Records,lists,Queues,setsand so on. LuaIt's all through .Tableto achieve. And inLuainTableVery good implementation of these data structures.

--Excerpt from: "programming in Lua"



look at the code below to make it clear that the use of tables in Lua is very clear:
--table in Lua, tableconfig = {hello= "Hello Lua", world= "World"}--Assignment mode 1, initialize config.words = "Hello" as key = value--Assignment Mode 2, Assign a value Config.num = 100 by specifying the form of Table.key = value--Specifying the type config["name"] = "Zhangsan"-Assignment mode 3 by assigning a value. Assign a value by table["key"] = value-Prints the value of the table in the form print (config["words") print (config.name) print (Config.hello)-through the for iterator, Traverse table, Output table key and value for key, Var in pairs (Config) doprint (Key,var) End

The following code uses a table to define an array, and a table can also define matrices and multidimensional arrays, linked lists, queues, and bidirectional queues, collections, and packages.
--Define an array to initialize. Here the type of each element is initialized to be different arr = {1,2,3,4, "Hello"}--the iterated algebraic group for Key, Var in pairs (arr) doprint (Key,var) end--define an empty table arr = {}--through for loop, Call the Insert method of table, insert the value into the array for var=1, and Dotable.insert (Arr,1,var) end--iterate over the array. The print key, the value for key, the Var in pairs (arr) doprint (Key,var) end--calls the table's API. Gets the maximum value of the array in print (TABLE.MAXN (arr))

Reader, be able to go to the address below to see the API that LUA provides to our developers. Now the latest LUA version number is 5.2:HTTP://WWW.LUA.ORG/MANUAL/5.2/





Here you can see the use of the corresponding API, the meaning of the detailed parameters.



Cocos2d-x scripting language LUA basic data structure-tables (table)

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.