Change in the handling of 'L->top' when calling metamethods
Instead of updating 'L->top' in every place that may call a metamethod, the metamethod functions themselves (luaT_trybinTM and luaT_callorderTM) correct the top. (When calling metamethods from the C API, however, the callers must preserve 'L->top'.)
This commit is contained in:
@@ -241,6 +241,23 @@ assert(a == 20 and b == false)
|
||||
a,b = T.testC("compare LE 5 -6, return 2", a1, 2, 2, a1, 2, 20)
|
||||
assert(a == 20 and b == true)
|
||||
|
||||
|
||||
do -- testing lessthan and lessequal with metamethods
|
||||
local mt = {__lt = function (a,b) return a[1] < b[1] end,
|
||||
__le = function (a,b) return a[1] <= b[1] end,
|
||||
__eq = function (a,b) return a[1] == b[1] end}
|
||||
local function O (x)
|
||||
return setmetatable({x}, mt)
|
||||
end
|
||||
|
||||
local a, b = T.testC("compare LT 2 3; pushint 10; return 2", O(1), O(2))
|
||||
assert(a == true and b == 10)
|
||||
local a, b = T.testC("compare LE 2 3; pushint 10; return 2", O(3), O(2))
|
||||
assert(a == false and b == 10)
|
||||
local a, b = T.testC("compare EQ 2 3; pushint 10; return 2", O(3), O(3))
|
||||
assert(a == true and b == 10)
|
||||
end
|
||||
|
||||
-- testing length
|
||||
local t = setmetatable({x = 20}, {__len = function (t) return t.x end})
|
||||
a,b,c = T.testC([[
|
||||
|
||||
Reference in New Issue
Block a user