Skip to content

Commit

Permalink
additional table tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tomblind committed Apr 3, 2022
1 parent 5ab3dc7 commit 445b298
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/tables/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,19 @@ local mt =
__len = function() return 42 end,
__add = function(self, other) return make() end,
__tostring = function() return "foobar" end,
__metatable = "hidden"
}

make = function()
return setmetatable({}, mt)
end

local empty = {}
local emptyWithMt = setmetatable({}, {__index = {foo = "FOO"}})
local emptyWithLenMt = setmetatable({}, {__len = function() return 42 end})
local emptyWithBadLenMt = setmetatable({}, {__len = function() error("FUBAR") end})
local emptyWithBadIndexMt = setmetatable({}, {__index = function(s, k) error("FUBAR") end})

local a = make()
local b = make()
print(#a) --0 in 5.1/jit, 42 in 5.2+
Expand Down

0 comments on commit 445b298

Please sign in to comment.