gopher-lua
gopher-lua copied to clipboard
__lt and __le can't compare table with number ,but it can be in lua5.1
- [x] GopherLua is a Lua5.1 implementation. You should be familiar with Lua programming language. Have you read Lua 5.1 reference manual carefully?
- [x] GopherLua is a Lua5.1 implementation. In Lua, to keep it simple, it is more important to remove functionalities rather than to add functionalities unlike other languages . If you are going to introduce some new cool functionalities into the GopherLua code base and the functionalities can be implemented by existing APIs, It should be implemented as a library.
Please answer the following before submitting your issue:
- What version of GopherLua are you using? :
- What version of Go are you using? :
- What operating system and processor architecture are you using? :win
- What did you do? : use metatable to compare table with number
- What did you expect to see? :
- What did you see instead? :
metatable func __lt and __le not work
local b = setmetatable({ _val = 10 }, {
__le = function(n, m)
local x = type(n) == 'table' and n._val or m._val
local val = type(n) ~= 'table' and n or m
print('__le:', x, val)
return x <= val
end,
__lt = function(n, m)
print('__lt:', n,m)
return 1
end,
})
and
print(b<1) -- it will report an error
but it can be run in lua5.1,see the pic bellow

Invoking __lt and __le for mixed types is a 5.2+ feature.