[Scummvm-git-logs] scummvm master -> 762ebd59dfc22fd7e3078425b8af3b08afed61ba
rvanlaar
noreply at scummvm.org
Fri Nov 24 21:49:17 UTC 2023
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
762ebd59df DIRECTOR: LINGO: improve lingo c_not
Commit: 762ebd59dfc22fd7e3078425b8af3b08afed61ba
https://github.com/scummvm/scummvm/commit/762ebd59dfc22fd7e3078425b8af3b08afed61ba
Author: Roland van Laar (roland at rolandvanlaar.nl)
Date: 2023-11-24T22:49:06+01:00
Commit Message:
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
Changed paths:
engines/director/lingo/lingo-code.cpp
engines/director/lingo/tests/if.lingo
diff --git a/engines/director/lingo/lingo-code.cpp b/engines/director/lingo/lingo-code.cpp
index fd18ab6c118..f657f4e710b 100644
--- a/engines/director/lingo/lingo-code.cpp
+++ b/engines/director/lingo/lingo-code.cpp
@@ -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);
}
diff --git a/engines/director/lingo/tests/if.lingo b/engines/director/lingo/tests/if.lingo
index 460e6dec14b..d10df061346 100644
--- a/engines/director/lingo/tests/if.lingo
+++ b/engines/director/lingo/tests/if.lingo
@@ -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
More information about the Scummvm-git-logs
mailing list