Debug

getconstant

通过基于 1 的索引从函数、堆栈级别或原型读取常量。

语法

getconstant(target: function | integer, index: number | integer): any | nil
别名 debug.getconstant

参数

名称类型描述
targetfunction | integer要检查的函数、堆栈级别或原型。
indexnumber | integer常量、原型、上值或堆栈槽内基于一的索引。

返回值

名称类型描述
constantany | nil所请求索引处的常量值,如果缺失则为零。

说明

通过基于 1 的索引从函数、堆栈级别或原型读取常量。

使用 2 个参数调用: target, index。参数表会说明哪些值必填,哪些值只用于细化行为。

返回 constant (any | nil)。使用返回表区分成功值、nil 结果和可恢复错误。

示例

使用占位值的示例调用。

local result = getconstant(1, 1)
print(result)