|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Mon May 25, 2009 1:03 am
[3.08] %isnumber reports falsely |
Tested this with the following steps:
1. Start CMUD, escape to a blank session.
2. Open Settings for the package editor.
3. Copy/paste this in Editor:
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<alias name="test" copy="yes">
<value>#IF (%isnumber($TestVar)) {#SAY "True."} {#SAY "False."}</value>
<arglist>TestVar</arglist>
</alias>
</cmud>
|
4. Close out settings, type 'test' on command line.
5. Type 'test 1' on the command line.
6. Type 'test a' on the command line.
As you can see, %isnumber is reporting true when there is no argument/variable. I tested this by using '#SAY %isnumber(@blah)' where @blah was not defined at all. It reported 1 instead of 0 or false.
Charneus |
|
|
|
wrym Magician
Joined: 06 Jul 2007 Posts: 349 Location: The big palace, My own lil world
|
Posted: Tue May 26, 2009 7:29 am |
I can confirm this behavior, but i'm not entirely convinced it's a bug.
Code: |
<alias name="test" language="Lua" id="325">
<value>print (type(zs.param(1)))</value>
<arglist>TestVar</arglist>
</alias>
|
Prints the type from Lua...
When you call this alias with no first parameter.... NOTHING is passed as first variable, and NOTHING... is well what?
In lua NOTHING is defined as it's on type, nil, so maybe in zscript since there is the %null, it should be of that type?
Your code can be written to account for that this way
Code: |
<alias name="test" id="325">
<value>#IF ($TestVar && %isnumber($TestVar)) {#SAY "True."} {#SAY "False."}</value>
<arglist>TestVar</arglist>
</alias> |
|
|
_________________ "To the engineer, all matter in the universe can be placed into one of two categories: (1) things that need to be fixed, and (2) things that will need to be fixed after you've had a few minutes to play with them" - Scott Adams, The Dilbert Principle |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Tue May 26, 2009 12:48 pm |
Nil is not a number, but a type, and your demonstration just proved it. %isnumber is falsely reporting that nil is a number, whereas in the past, it never has. Furthermore, whenever a variable is empty or doesn't exist, zscript has always treated that as %null. NOTHING is not a number. NOTHING does not equal 0. Therefore, this is a bug. :P
Charneus |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Mon Jun 01, 2009 6:36 pm |
Confirmed and added to bug list.
|
|
|
|
|
|