[Scummvm-git-logs] scummvm master -> e503e2dcea04e4d740cf81f90cb19c7317f33ceb

rvanlaar roland at rolandvanlaar.nl
Fri Jul 31 20:16:57 UTC 2020


This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
b44b5321d5 DIRECTOR: LINGO: scummvmAsserts improvement
f17efd5c39 DIRECTOR: LINGO: Implement charOf and charToOf
e503e2dcea DIRECTOR: LINGO: fix compiler warning


Commit: b44b5321d571cca6a3db04bb155ff8c6dc38f4e4
    https://github.com/scummvm/scummvm/commit/b44b5321d571cca6a3db04bb155ff8c6dc38f4e4
Author: Roland van Laar (roland at rolandvanlaar.nl)
Date: 2020-07-31T22:16:44+02:00

Commit Message:
DIRECTOR: LINGO: scummvmAsserts improvement

- Remove the lingo return value. Prevents it being dropped.
- set message of scummvmAssertEqual to show which values don't equal.

Changed paths:
    engines/director/lingo/lingo-builtins.cpp


diff --git a/engines/director/lingo/lingo-builtins.cpp b/engines/director/lingo/lingo-builtins.cpp
index 498c4fed60..fcdae67166 100644
--- a/engines/director/lingo/lingo-builtins.cpp
+++ b/engines/director/lingo/lingo-builtins.cpp
@@ -2435,7 +2435,6 @@ void LB::b_scummvmassert(int nargs) {
 		warning("LB::b_scummvmassert: is false");
 	}
 	assert(d.asInt() != 0);
-	g_lingo->push(d);
 }
 
 void LB::b_scummvmassertequal(int nargs) {
@@ -2444,10 +2443,9 @@ void LB::b_scummvmassertequal(int nargs) {
 
 	int result = d1.equalTo(d2);
 	if (!result) {
-		warning("LB::b_scummvmassertequals: is false");
+		warning("LB::b_scummvmassertequals: %s is not equal %s", d1.asString(), d2.asString());
 	}
 	assert(result == 1);
-	g_lingo->push(Datum(result));
 }
 
 } // End of namespace Director


Commit: f17efd5c39744ff88f15d91476762ccc664edc72
    https://github.com/scummvm/scummvm/commit/f17efd5c39744ff88f15d91476762ccc664edc72
Author: Roland van Laar (roland at rolandvanlaar.nl)
Date: 2020-07-31T22:16:44+02:00

Commit Message:
DIRECTOR: LINGO: Implement charOf and charToOf

Includes tests in strings.lingo.
The tests verify that the scummvm implementation follows
the warts of the D4 one.

Changed paths:
    engines/director/lingo/lingo-code.cpp
    engines/director/lingo/tests/strings.lingo


diff --git a/engines/director/lingo/lingo-code.cpp b/engines/director/lingo/lingo-code.cpp
index 16c54c2000..ac0c1b0301 100644
--- a/engines/director/lingo/lingo-code.cpp
+++ b/engines/director/lingo/lingo-code.cpp
@@ -1038,22 +1038,56 @@ void LC::c_of() {
 }
 
 void LC::c_charOf() {
-	Datum d2 = g_lingo->pop();
-	Datum d1 = g_lingo->pop();
+	Datum d2 = g_lingo->pop(); // string
+	Datum d1 = g_lingo->pop(); // index
 
-	warning("STUB: LC::c_charOf(): %d %d", d1.u.i, d2.u.i);
+    if (d1.type != INT || d2.type != STRING ) {
+		warning("LC::c_charOf(): Called with wrong data types: %s and %s", d1.type2str(), d2.type2str());
+		g_lingo->push(Datum(""));
+		return;
+	}
 
-	g_lingo->push(d1);
+	Datum res;
+	int index = d1.u.i;
+	Common::String chunkExpr = *d2.u.s;
+
+	if (index < 1)
+		res = Datum(chunkExpr);
+	else if (uint(index) > chunkExpr.size())
+		res = Datum("");
+	else
+		res = Datum(Common::String(chunkExpr[index - 1]));
+	g_lingo->push(res);
 }
 
 void LC::c_charToOf() {
-	Datum d3 = g_lingo->pop();
-	Datum d2 = g_lingo->pop();
-	Datum d1 = g_lingo->pop();
+	Datum d3 = g_lingo->pop(); // string
+	Datum d2 = g_lingo->pop(); // indexFrom
+	Datum d1 = g_lingo->pop(); // indexTo
+
+	if (d1.type != INT || d2.type != INT || d3.type != STRING) {
+		warning("LC::c_charToOf(): Called with wrong data types: %s, %s and %s", d1.type2str(), d2.type2str(), d3.type2str());
+		g_lingo->push(Datum(""));
+		return;
+	}
 
-	warning("STUB: LC::c_charToOf(): %d %d %d", d1.u.i, d2.u.i, d3.u.i);
+	int indexFrom = d1.u.i;
+	int indexTo = d2.u.i;
+	Common::String chunkExpr = *d3.u.s;
 
-	g_lingo->push(d1);
+	Datum res;
+	// The if order is important. It mimicks the checks, i.e. bugs, of Director 4.
+	if (indexFrom < 0)
+		res = Datum(chunkExpr);
+	else if (indexTo < 0)
+		res = Datum(Common::String(chunkExpr[indexTo - 1])); // treat as charOf
+	else if (indexFrom > indexTo)
+		res = Datum("");
+	else if (uint(indexFrom) > chunkExpr.size())
+		res = Datum("");
+	else
+		res = Datum(chunkExpr.substr(indexFrom - 1, indexTo - 1));
+	g_lingo->push(res);
 }
 
 void LC::c_itemOf() {
diff --git a/engines/director/lingo/tests/strings.lingo b/engines/director/lingo/tests/strings.lingo
index ef971d4434..b406a652c7 100644
--- a/engines/director/lingo/tests/strings.lingo
+++ b/engines/director/lingo/tests/strings.lingo
@@ -34,3 +34,40 @@ scummvmAssertEqual(test, return & "foo" & return)
 
 put return into test
 scummvmAssertEqual(test, return)
+
+-- LC::charOF
+set string to "Macromedia"
+set res to char 6 of string
+scummvmAssertEqual(res, "m")
+put "m" && res
+
+-- error and bounds checks
+set res to  char 60 of string
+scummvmAssertEqual(res, EMPTY)
+put "" && res
+set res to char 0 of string
+scummvmAssertEqual(res, string)
+put string && res
+
+-- LC::charToOf
+set string to "Macromedia"
+set res to char 6 to 9 of string
+put "media" && res
+scummvmAssertEqual(res, "media")
+
+-- error and bounds checks
+set res to char 6 to 5 of string
+put "" && res
+scummvmAssert(res="")
+
+set res to char 6 to 60 of string
+put "media" && res
+scummvmAssertEqual(res, "media")
+
+set res to char -1 to -2 of string
+put string && res
+scummvmAssertEqual(res, string)
+
+set res to char 50 to 60 of string
+put "" && res
+scummvmAssertEqual(res, "")


Commit: e503e2dcea04e4d740cf81f90cb19c7317f33ceb
    https://github.com/scummvm/scummvm/commit/e503e2dcea04e4d740cf81f90cb19c7317f33ceb
Author: Roland van Laar (roland at rolandvanlaar.nl)
Date: 2020-07-31T22:16:44+02:00

Commit Message:
DIRECTOR: LINGO: fix compiler warning

Changed paths:
    engines/director/lingo/lingo-builtins.cpp


diff --git a/engines/director/lingo/lingo-builtins.cpp b/engines/director/lingo/lingo-builtins.cpp
index fcdae67166..17d82cdbb2 100644
--- a/engines/director/lingo/lingo-builtins.cpp
+++ b/engines/director/lingo/lingo-builtins.cpp
@@ -2443,7 +2443,7 @@ void LB::b_scummvmassertequal(int nargs) {
 
 	int result = d1.equalTo(d2);
 	if (!result) {
-		warning("LB::b_scummvmassertequals: %s is not equal %s", d1.asString(), d2.asString());
+		warning("LB::b_scummvmassertequals: %s is not equal %s", d1.asString().c_str(), d2.asString().c_str());
 	}
 	assert(result == 1);
 }




More information about the Scummvm-git-logs mailing list