参考链接:
https://www.jianshu.com/p/78f0e050ddad
TestRawGetSet.lua
1 function TestRawGetSet() 2 --rawget & rawset:绕过元表,直接获取或设置table的值 3 local a = {a1 = 10} 4 setmetatable(a, { 5 __index = {a2 = 20}, 6 __newindex = function (t, key, value) 7 print(key .. "_" .. value) 8 end 9 }) 10 11 print(a.a2) --20 12 print(rawget(a, "a2")) --nil 13 14 a.a3 = 30 --a3_30 15 print(a.a3) --nil 16 rawset(a, "a3", 40) 17 print(a.a3) --40 18 end 19 20 TestRawGetSet()