- Lua Quick Start Guide
- Gabor Szauer
- 321字
- 2021-08-05 10:30:36
Basic types
In the last section, you were introduced to the concepts of a variable and a value. This section explores the concept of what a value is. Every value has a data type, which intuitively describes what kind of data the value holds. Lua supports eight basic value types:
- nil: The absence of data. This type represents literal nothingness. If a certain piece of data is invalid or unknown, nil is usually the best way to represent that it is invalid or unknown.
- Boolean: A value of true or false. A Boolean value is binary and can only ever be in one of two states, true or false.
- number: A number can represent any real number: 0, -1, 5, or even decimals such as 3.14159265359.
- string: A string is an array of characters. When declaring a string literal, it must be "enclosed within quotation marks."
- function: A function is some code that is referred to by a name and can be executed any time.
- table: A table contains information using key-value pairs. Tables will be covered in depth in Chapter 3, Tables and Objects.
- userdata: Complex data structures defined in the C programming language.
- thread: Threads can be used to execute code in parallel. Instead of your code running one set of commands, it can run several sets of commands at the same time.
This section will explore the nil, Boolean, and number types. The string and function types will get their own sections in this chapter. The table type is so important it will have its own chapter.
Lua uses loose, implicit types. That means a variable can have any type. Once a variable is assigned a type, it can be assigned any other type. For example, it is valid to assign a number to a variable that holds a string. After the assignment, the variable will simply hold a number.
推薦閱讀
- 算法零基礎一本通(Python版)
- Linux核心技術從小白到大牛
- R語言數據可視化實戰
- 前端架構:從入門到微前端
- Python高效開發實戰:Django、Tornado、Flask、Twisted(第3版)
- Spring+Spring MVC+MyBatis整合開發實戰
- 用戶體驗增長:數字化·智能化·綠色化
- Visual Basic程序設計實驗指導(第二版)
- Java Web開發詳解
- 微服務架構深度解析:原理、實踐與進階
- Python 3 數據分析與機器學習實戰
- Go語言入門經典
- Mastering Embedded Linux Programming
- TypeScript全棧開發
- Beginning C# 7 Hands-On:The Core Language