国际访客建议访问 Primers 编程伙伴 国际版站点 > Lua 教程 > type 以获得更好的体验。

# Lua 的 type 函数

请查看 Lua 标准库函数列表 了解更多相关 API。
type (v)

!subtitle:说明

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

!subtitle:参数

  • v - 要获取类型的值

!subtitle:返回值

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

# 示例

运行示例

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)))

# 推荐阅读

type - Lua 5.4 Reference Manual

本文 更新于: 2025-11-27 09:38:12 创建于: 2025-11-27 09:38:12