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

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.
主站蜘蛛池模板: 辽宁省| 河西区| 宜都市| 聂荣县| 云南省| 新余市| 奉新县| 库尔勒市| 信宜市| 奎屯市| 沈丘县| 滦南县| 遂平县| 紫阳县| 汉川市| 庆阳市| 凌源市| 扶绥县| 凉城县| 平昌县| 南安市| 柳江县| 耿马| 襄汾县| 扶风县| 玛曲县| 德惠市| 阜新市| 三门县| 蒙自县| 永寿县| 白玉县| 黄冈市| 赤壁市| 五大连池市| 廉江市| 沅陵县| 美姑县| 双峰县| 柯坪县| 阿坝|