[Scummvm-git-logs] scummvm rvanlaar/getAt -> 484e1faeef2a401b129d87b1d55ab51cfdb7b722
rvanlaar
roland at rolandvanlaar.nl
Sun Apr 5 21:38:30 UTC 2020
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:
484e1faeef DIRECTOR:LINGO: Implement getAt
Commit: 484e1faeef2a401b129d87b1d55ab51cfdb7b722
https://github.com/scummvm/scummvm/commit/484e1faeef2a401b129d87b1d55ab51cfdb7b722
Author: Roland van Laar (roland at rolandvanlaar.nl)
Date: 2020-04-05T23:36:56+02:00
Commit Message:
DIRECTOR:LINGO: Implement getAt
Builtin getAt gets the nth item in a 1 indexed list.
getAt treats a float as int floor(float).
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 747022febb..41fd552b46 100644
--- a/engines/director/lingo/lingo-builtins.cpp
+++ b/engines/director/lingo/lingo-builtins.cpp
@@ -649,8 +649,31 @@ void LB::b_getaProp(int nargs) {
}
void LB::b_getAt(int nargs) {
- g_lingo->printSTUBWithArglist("b_getAt", nargs);
- g_lingo->dropStack(nargs);
+ if (nargs != 2) {
+ warning("b_getAt: expected 2 args, not %d", nargs);
+ g_lingo->dropStack(nargs);
+ return;
+ }
+ Datum index = g_lingo->pop();
+ Datum list = g_lingo->pop();
+ if (index.type == FLOAT)
+ index.toInt();
+
+ if (index.type != INT) {
+ warning("b_getAt: index arg should be of type INT or FLOAT, not %s", index.type2str());
+ return;
+ }
+ if (list.type != ARRAY) {
+ warning("b_getAt: list arg should be of type ARRAY, not %s", list.type2str());
+ return;
+ }
+ if (index.u.i-1 < 0 || index.u.i > list.u.farr->size()){
+ warning("b_getAt: index %s out of bounds", index.type2str());
+ return;
+ }
+
+ Datum result = list.u.farr->operator[](index.u.i-1);
+ g_lingo->push(result);
}
void LB::b_getLast(int nargs) {
More information about the Scummvm-git-logs
mailing list