R3dclaw
|
  |
| Joined: 28 Nov 2014 |
| Total Posts: 14 |
|
|
| 06 Oct 2016 01:55 AM |
| Just started learning Lua, and I stumbled upon this: x=y==x |
|
|
| Report Abuse |
|
|
|
| 06 Oct 2016 01:59 AM |
Sure.
Before anything, x and y are both nil
"y == x"
This uses the equality operator (double equals sign). Now, since y and x are both nil, the statement y == x is true.
Now we are setting x to the value of y == x, x becomes true, and y is nil.
This is very confusing and nobody should ever use this in real code. |
|
|
| Report Abuse |
|
|
|
| 06 Oct 2016 02:01 AM |
how is it confusing? all relational operators (==, >=, <=, ~=, <, >) return a boolean, it's very simple
local x = 5 local y = 6 local isequal = x == y
The `x == y` is evaluated first and returns false, thus `isequal` is set to false |
|
|
| Report Abuse |
|
|
R3dclaw
|
  |
| Joined: 28 Nov 2014 |
| Total Posts: 14 |
|
|
| 06 Oct 2016 02:10 AM |
| It is pretty confusing actually, despite being slightly faster. Not as much non understandable as much as it looks weird at first glance. |
|
|
| Report Abuse |
|
|
|
| 06 Oct 2016 02:18 AM |
| faster than what, exactly? |
|
|
| Report Abuse |
|
|
R3dclaw
|
  |
| Joined: 28 Nov 2014 |
| Total Posts: 14 |
|
| |
|
|
| 06 Oct 2016 02:28 AM |
| not by much, very insignificantly. just an extra jump most likely |
|
|
| Report Abuse |
|
|
R3dclaw
|
  |
| Joined: 28 Nov 2014 |
| Total Posts: 14 |
|
|
| 06 Oct 2016 02:43 AM |
| Still is considerable when in loops that repeat many times. |
|
|
| Report Abuse |
|
|
|
| 06 Oct 2016 02:44 AM |
| Not really considering why would you ever have to continuously set a variable to true/false depending on whether or not it's equal? Mostly you're just checking it is't non-falsey (i.e. if x then) |
|
|
| Report Abuse |
|
|