1 -- __newindex 对表进行更新 2 MyMetatable = {} 3 MyTable = setmetatable({["newKey"] = 12}, {__newindex = MyMetatable}) 4 MyTable.newKey1 = 156 5 print(MyTable.newKey1) --- nil 6 print(MyMetatable.newKey1) --- 156
1 -- __newindex 对表进行更新 2 MyMetatable = {} 3 MyTable = setmetatable({["newKey"] = 12}, {__newindex = MyMetatable}) 4 MyTable.newKey1 = 156 5 print(MyTable.newKey1) --- nil 6 print(MyMetatable.newKey1) --- 156