tessel / colony-compiler

[UNMAINTAINED] "Compiles" JS to Lua to run on Colony.
Other
80 stars 16 forks source link

No differentiation between equality (==) and identity (===). #18

Open paulcuth opened 10 years ago

paulcuth commented 10 years ago

JavaScript has two distinct relational operators, == and ===, but colony is currently treating them as the same.

JavaScript:

console.log(0 == false, 0 === false);   // --> true, false

Colony output:

--...
console:log((((0))==((false))), (((0))==((false))));
--...

Maybe there should be runtime functions that perform these comparisons rather than using Lua's built-in operators that coerce in slightly different ways or have different behaviours altogether?

console:log(_equal(((0)),((false))), _identical(((0)),((false))));
paulcuth commented 10 years ago

Alternatively you could create Lua classes for each JavaScript primitive type and use __eq metamethods to handle coercions and comparisons correctly. This does not negate, however, the need to add functionality to handle identity comparisons.