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

Types of values

Lua is a dynamically typed language. There is no defined variable type in the language. This allows each value to carry 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 have them returned as results.

The basic types of values that you'll deal with are as follows:

  • Nil: This 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: This 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: These represent real (double-precision, floating-point) numbers.
  • String: This is a sequence of characters. 8-bit characters and embedded zeroes are allowed.
  • Tables: These are data structures in Lua. They are 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 (more information on this later in this chapter called Tables).
  • Functions: These are known as first-class values of Lua. Typically, functions can be stored in variables, passed as arguments to other functions, and returned as results.
主站蜘蛛池模板: 旬阳县| 安顺市| 扎兰屯市| 田林县| 称多县| 林西县| 泸溪县| 九龙城区| 新安县| 大关县| 天津市| 西城区| 宁河县| 曲麻莱县| 聂拉木县| 资阳市| 达州市| 余干县| 周宁县| 库尔勒市| 专栏| 杂多县| 邵阳县| 星子县| 景宁| 固始县| 邯郸县| 桃源县| 大化| 濮阳县| 内丘县| 虞城县| 射洪县| 上犹县| 大连市| 天峨县| 深州市| 洛阳市| 新竹市| 阿尔山市| 卫辉市|