约 618 字

约 3 分钟

#Lua 的 type 函数

type (v)

说明

获取 v 的类型;返回的结果是字符串:"nil","number","string","boolean","table","function","thread","userdata"。

参数

  • v - 要获取类型的值

返回值

  • 返回字符串形式的类型名

#示例

print(type(nil))
print(type(10))
print(type('hello world'))
print(type(true))
print(type({}))
print(type(function() end))
print(type(coroutine.create (function() end)))

>>> Establishing WebAssembly Runtime.

>>> Standby.

Powered by Shift.

#推荐阅读

type - Lua 5.4 Reference Manual

更新: 2026/2/6

作者: PlanC

创建: 2025/10/30