What does operator ~= mean in Lua?

53,797

Solution 1

the ~= is not equals

It is the equivalent in other languages of !=

Solution 2

The operator ~= is exactly the negation of equality (==).

See docs.

Solution 3

During compilation it gets translated to not a == b.

Solution 4

~= in Lua, is just like doing != in other languages like C#.

Share:
53,797
Alejandro Simkievich
Author by

Alejandro Simkievich

Passionate entrepreneur. Love being at the intersection of business and technology. Interests include machine learning, artificial intelligence, natural language processing and computer vision.

Updated on July 09, 2022

Comments

  • Alejandro Simkievich
    Alejandro Simkievich almost 2 years

    What does the ~= operator mean in Lua?

    For example, in the following code:

    if x ~= params then
    
  • Alejandro Simkievich
    Alejandro Simkievich over 8 years
    thanks a lot caulitomaz. yes, it makes a lot of sense - almost obvious in retrospective.
  • Alejandro Simkievich
    Alejandro Simkievich over 8 years
    thanks a lot for pointing to the docs pushkin - for some reason googling ~= did not work for me. But now that I see the code, it makes a lot of sense.
  • Brant Sterling Wedel
    Brant Sterling Wedel over 6 years
    Makes no sense actually, since ~ is the mathematical symbol of approximately equal ... would maybe make sense if it was the same as an == in js tho :p
  • Brant Sterling Wedel
    Brant Sterling Wedel over 6 years
    I suppose on second thought A != B mathematically means factorial of A is equal to B ... so maybe I can forgive Lua being written in C but not just using the C style != operator :p