github.com/arnodel/golua@v0.0.0-20230215163904-e0b5347eaaa1/lib/base/lua/setmetatable.lua (about) 1 local function test(...) 2 local ok, val = pcall(setmetatable, ...) 3 if ok then 4 print("ok") 5 else 6 print(val) 7 end 8 end 9 10 test() 11 --> ~.*: 2 arguments needed 12 13 test(1) 14 --> ~.*: 2 arguments needed 15 16 test(1, 2) 17 --> ~.*must be a table 18 19 t = {} 20 setmetatable(t, {__metatable={}}) 21 test(t, nil) 22 --> ~.*: cannot set metatable 23 24 t = {} 25 test(t, nil) 26 --> =ok 27 28 test(t, 123) 29 --> ~.*must be a table