官术网_书友最值得收藏!

Types of values

Lua is a dynamically typed language. There is no defined type in the language. Each value carries its own type.

As you have noticed, values can be stored in variables. They can be manipulated to give a value of any type. This also allows you to pass arguments to other functions and return as results.

The basic types of values that you'll deal with are the following:

  • nil—It is the only type whose value is nil. Any uninitialized variable has nil as its value. Like global variables, it is nil by default and can be assigned nil to delete it.
  • Boolean—The Boolean type has two values, false and true. You will notice that conditional expressions consider false and nil as false and anything else as true.
  • Numbers—Represents real (double-precision floating-point) numbers.
  • String—A String is a sequence of characters. 8-bit characters and embedded zeros are allowed.
  • Tables—A data structure in Lua. It is implemented by an associative array, which is an array that can be indexed not only with numbers, but also with strings or any other value, except nil. (We will discuss more about this in the section Tables later in this chapter).
  • Functions—Known as first-class values of Lua. Typically, functions can be stored in variables, passed as arguments to other functions and returned as results.
主站蜘蛛池模板: 甘南县| 土默特左旗| 深水埗区| 上蔡县| 开远市| 武胜县| 东安县| 嘉峪关市| 新龙县| 绩溪县| 侯马市| 罗城| 揭西县| 出国| 鄂托克旗| 韶山市| 遵义市| 元氏县| 南陵县| 温宿县| 宝坻区| 嘉定区| 富锦市| 交口县| 扶风县| 德州市| 繁昌县| 通辽市| 肥乡县| 临猗县| 西安市| 汕头市| 靖宇县| 台南县| 长海县| 本溪| 临邑县| 昭苏县| 磐安县| 兴化市| 渑池县|