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

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.
主站蜘蛛池模板: 嵊州市| 湖南省| 全椒县| 凤冈县| 从化市| 濉溪县| 泽库县| 延津县| 城市| 揭西县| 宁安市| 工布江达县| 太白县| 长治市| 浦城县| 左贡县| 乌兰察布市| 睢宁县| 徐闻县| 尼玛县| 洛南县| 翁牛特旗| 齐齐哈尔市| 乳山市| 通江县| 玛纳斯县| 四平市| 治县。| 高密市| 砀山县| 育儿| 乌兰察布市| 博兴县| 衡东县| 乐至县| 诏安县| 长春市| 正定县| 邯郸县| 邻水| 章丘市|