DIRECTOR: LINGO: improve lingo c_not

It's a bit unexpected, but `not` works differently then the inverse of
`if`.

After testing in D4.0.4 the following two statements are true:

    defined variables are falsy when checked with not
        i.e. not varundefined => true and not vardefined => false
    only a var with value 0 is seen as false when checked with not
        i.e. not 0 => true
This commit is contained in:
Roland van Laar committed 2023-11-24 22:49:06 +01:00
1 parent 318dda4884
commit 762ebd59df
2 files changed
+24 -1

No files matched your search

+7 -1
View File
@@ -1226,9 +1226,15 @@ void LC::c_or() {
}
void LC::c_not() {
// Not returns true when a variable is undefined or is an int and is zero.
Datum res;
Datum d = g_lingo->pop();
Datum res(d.asInt() == 0 ? 1 : 0);
if ((d.type == INT && d.u.i == 0) || d.type == VOID) {
res = Datum(1);
} else {
res = Datum(0);
}
g_lingo->push(res);
}
+17
View File
@@ -7,6 +7,23 @@ if x = 6 then put 2
set y = 4
-- defined variables are falsy when checked with not
-- i.e. not varundefined => true
-- only a var with value 0 is seen as false when checked with not
-- i.e. not 0 => true
scummvmAssert(varundefined = 0)
scummvmAssert(not varundefined = 1)
set a to 0
scummvmAssert(not a = 1)
set a to 0.0
scummvmAssert(not a = 0)
set a to "string"
scummvmAssert(not a = 0)
set parray to [#pt: 1, #ar: 0]
scummvmAssert(not parray = 0)
--
repeat with x = 1 to 6
if x = 3 then put 30
else if x = 4 then put 40