类型 函数 库 (全局) 返回值 字符串 修订 版本 2024.3703 关键词 type, 数据类型
返回其参数的类型。可能的结果为:
"nil"
(一个字符串,而不是 nil
值)"number"(数字)
"string"(字符串)
"boolean"(布尔值)
"table"(表)
"function"(函数)
"thread"(线程)
"userdata"(用户数据)
type( v )
要确定其类型的项目。
local t = {} local n = 123 local s = "Hello world!" local b = true local function f() return "this is a string"; end local type_t = type( t ) -- "table" local type_n = type( n ) -- "number" local type_s = type( s ) -- "string" local type_b = type( b ) -- "boolean" local type_f1 = type( f ) -- "function" local type_f2 = type( f() ) -- "string"