type()

类型 函数
(全局)
返回值 字符串
修订 版本 2024.3703
关键词 type, 数据类型

概述

返回其参数的类型。可能的结果为:

语法

type( v )
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"