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

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.
主站蜘蛛池模板: 威海市| 财经| 内黄县| 长寿区| 朔州市| 郴州市| 靖安县| 石景山区| 古浪县| 石河子市| 楚雄市| 孟州市| 芮城县| 宾阳县| 吉木萨尔县| 垣曲县| 石台县| 云安县| 黎平县| 汾阳市| 健康| 咸丰县| 弥渡县| 鹤庆县| 桑日县| 富裕县| 昌宁县| 赫章县| 衡水市| 莱阳市| 连平县| 清涧县| 南皮县| 抚顺县| 孙吴县| 邵阳县| 随州市| 雅江县| 普格县| 井研县| 青川县|