539

3 分钟

#Lua 的 rawget 函数

rawget (table, index)

说明

获取表 tableindex 字段值,不会触发元表的 __index 字段。

参数

  • table - 要读取的表
  • index - 索引

返回值

  • table[index] 的原始值

#示例

local v = { } -- 定义元表,包含 __index 元方法 local metatable = { __index = function(t, key) return key end } -- 设置元表 setmetatable(v, metatable) -- 读取字段 print("v['key'] is ", v['key']) print("rawget(v, 'key') is", rawget(v, 'key'))

>>> Establishing WebAssembly Runtime.

>>> Standby.

Powered by Shift.

#推荐阅读

rawget - Lua 5.4 Reference Manual

创建于 2025/10/3

更新于 2025/10/3