基本类型

类型初始化

-- 整数:64 位
local number = 42
-- number = 42
-- 十六进制字面量
local mb = 0x100000
-- mb = 1048576

-- 有小数点或指数就是浮点数
local exp = 2.71828
-- exp = 2.71828
local billion = 1e9
-- billion = 1000000000.0

-- 单引号和双引号没有区别
local greeting = 'Hello'
-- greeting = Hello
-- 引号内用 \n,或用长括号
local text1 = "this is some\nmultiLine text"
-- text1 = this is some
-- multiLine text
local text2 = [[this is some
multiLine text]]
-- text2 = this is some
-- multiLine text

local sun_is_star = true
-- sun_is_star = true
local earth_is_star = false
-- earth_is_star = false

-- 字符是只有一个字母的字符串
local char_a = "A" -- 也可以写 "\65" 或 "\u{41}"
-- char_a = A

-- 完全没有值
local nothing = nil
-- nothing = nil

print("number = " .. number)
print("mb = " .. mb)
print("exp = " .. exp)
print("billion = " .. billion)
print("greeting = " .. greeting)
print("text1 = " .. text1)
print("text2 = " .. text2)
print("sun_is_star = " .. tostring(sun_is_star))
print("earth_is_star = " ..
      tostring(earth_is_star))
print("char_a = " .. char_a)
print("nothing = " .. tostring(nothing))