Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__lt and __le can't compare table with number ,but it can be in lua5.1 #317

Open
2 tasks done
rhettli opened this issue Apr 27, 2021 · 1 comment
Open
2 tasks done

Comments

@rhettli
Copy link

rhettli commented Apr 27, 2021

  • GopherLua is a Lua5.1 implementation. You should be familiar with Lua programming language. Have you read Lua 5.1 reference manual carefully?
  • 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:

  1. What version of GopherLua are you using? :
  2. What version of Go are you using? :
  3. What operating system and processor architecture are you using? :win
  4. What did you do? : use metatable to compare table with number
  5. What did you expect to see? :
  6. 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

Screenshot 2021-04-27 164610

@tongson
Copy link
Contributor

tongson commented Jun 6, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants