lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




On Sun, Feb 22, 2009 at 2:03 PM, Duncan Cross <duncan.cross@gmail.com> wrote:

On Sun, Feb 22, 2009 at 12:34 PM, David Given <dg@cowlark.com> wrote:
You know how we (well, I) keep saying that _javascript_ has almost
identical semantics to Lua? Well, unfortunately that's not the case. I'm
trying to port a program in _javascript_ to Lua that's making extensive
use of some of these semantics and I'm not sure how to emulate them.

There's two so far that are biting me:

(a) the _javascript_ special values undefined and null are type compatible
with numbers, so (0 > null) is valid (and false)

(_javascript_)
assert(value == undefined)
assert(!((value < 0) || (value > 0) || (value == 0)))

As far as I know there's very little you can do about this except wrap every "if" condition and "and"/"or" operand in a call to this:

local function jstrue(n)  return (n and n ~= 0);  end

...ugly - and will also break if you want (a || b) to return zero when a is false and b is zero, as the conversion (jstrue(a) or jstrue(b)) will evaluate to false.

I'm sorry about this bit, I skimmed over what you said and responded in non-sequitur, talking about 0 evaluating to nil/false rather than the other way around. That's an even bigger problem - you cannot override the comparison of two distinct Lua data types, so even giving boolean and nil custom metamethods won't help.
 
-Duncan