Lua variables to understand learning _Two ----

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/weixin_42509907/article/details/102752563

Lua variables

  • Global Variables
  • Local variables
  • Table field
  1. Variable outside the function are the default global variables, unless a local display Description
  2. Function parameters within the function variables and local variables default
  3. The role of local variable declarations from the beginning to the end of the statement block, then deletes to nil
  4. Variable Default nill
  • Variable assignment
  1. a = "sda" ... "ads" result "sadads"
  2. a,b = 1,5 a=1,b=5
  3. Ab values ​​can be exchanged by a, b = b, a
  4. When the number variable> variable number of complement by number value nil
    • a, b = 4 Provisions a = 4, b = nil
  5. When the number of variables <extra number value are ignored
    • a, b = 4,5,6,7 a = 4, b = 5 6,7 discarded
  6. Without initialize variables may be used, a default value is nil
    • print(s) nil
  • index
  1. And the use of the index table []
  2. site[“key”] = “csdn.net”
  3. The same result print (site [ "key"]) and print (site.key)
  4. The index is a string to use table.index

Rules identifier defines substantially the same as C

Lua identifier used to define a variable, user-defined functions for additional items. After the identifier to a letter A to Z a to z, or the beginning or underscore _ plus zero or more letters, digits, (0 to 9).

Best not to increase the use underscores to write letters identifier, because Lua reserved words is the same.

Lua is not allowed to use special characters such as @, $, and% defined identifier. Lua is a case-sensitive programming language. Therefore, in Lua Runoob with runoob are two different identifiers. Here are some correct identifier:

Guess you like

Origin blog.csdn.net/weixin_42509907/article/details/102752563