[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: More on comparing strings and numbers
- From: Rici Lake <lua@...>
- Date: Fri, 15 Dec 2006 10:40:37 -0500
On 15-Dec-06, at 10:33 AM, Steve Heller wrote:
Ok, let me try this again.
I have code that says something like:
if X == "" or X == 0 then X = 9999
I want this to work as intended, i.e., if the value of
X is "" or 0, then it will be changed to 9999.
However, I don't have any way of telling whether the
existing value of X is a string or a number. I
have hundreds of these expressions, and don't want to
change each one to test the type of the variable
before doing the comparisons. Is there any way to do
this without modifying all these expressions?
That will work fine, as long as the comparision is == or ~=.
In Lua, *values* have a type, not "locations" or "variables".
Any two values can be compared for equality (and they are unequal if
they are of different types). Only ordered comparisons between
different types will raise an error.