Deprecated the emulation of '__le' using '__lt'
As hinted in the manual for Lua 5.3, the emulation of the metamethod for '__le' using '__le' has been deprecated. It is slow, complicates the logic, and it is easy to avoid this emulation by defining a proper '__le' function. Moreover, often this emulation was used wrongly, with a programmer assuming that an order is total when it is not (e.g., NaN in floating-point numbers).
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
-- $Id: testes/coroutine.lua $
|
||||
-- $Id: testes/coroutine.lua 2018-07-25 15:31:04 -0300 $
|
||||
-- See Copyright Notice in file all.lua
|
||||
|
||||
print "testing coroutines"
|
||||
@@ -619,10 +619,8 @@ end
|
||||
|
||||
assert(run(function () if (a>=b) then return '>=' else return '<' end end,
|
||||
{"le", "sub"}) == "<")
|
||||
-- '<=' using '<'
|
||||
mt.__le = nil
|
||||
assert(run(function () if (a<=b) then return '<=' else return '>' end end,
|
||||
{"lt"}) == "<=")
|
||||
{"le", "sub"}) == "<=")
|
||||
assert(run(function () if (a==b) then return '==' else return '~=' end end,
|
||||
{"eq"}) == "~=")
|
||||
|
||||
@@ -677,7 +675,7 @@ do -- a few more tests for comparsion operators
|
||||
return val(a) < val(b)
|
||||
end,
|
||||
}
|
||||
local mt2 = { __lt = mt1.__lt } -- no __le
|
||||
local mt2 = { __lt = mt1.__lt, __le = mt1.__le }
|
||||
|
||||
local function run (f)
|
||||
local co = coroutine.wrap(f)
|
||||
|
||||
Reference in New Issue
Block a user