aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorAlyssa Milburn2011-07-07 16:20:01 +0200
committerAlyssa Milburn2011-07-07 16:23:34 +0200
commite4fc8e85ed30217ee537c178e01d5a980ba0f14a (patch)
tree30e57ae80bd3228c3914c48cad7b2b6150649107 /engines
parent33a85af915bed7db63561f54ee5848aa7792fcbc (diff)
downloadscummvm-rg350-e4fc8e85ed30217ee537c178e01d5a980ba0f14a.tar.gz
scummvm-rg350-e4fc8e85ed30217ee537c178e01d5a980ba0f14a.tar.bz2
scummvm-rg350-e4fc8e85ed30217ee537c178e01d5a980ba0f14a.zip
MOHAWK: Implement stringLen and substring LBCode functions.
Diffstat (limited to 'engines')
-rw-r--r--engines/mohawk/livingbooks_code.cpp29
-rw-r--r--engines/mohawk/livingbooks_code.h2
2 files changed, 29 insertions, 2 deletions
diff --git a/engines/mohawk/livingbooks_code.cpp b/engines/mohawk/livingbooks_code.cpp
index e9ef2516e2..6531f65753 100644
--- a/engines/mohawk/livingbooks_code.cpp
+++ b/engines/mohawk/livingbooks_code.cpp
@@ -686,8 +686,8 @@ struct CodeCommandInfo {
CodeCommandInfo generalCommandInfo[NUM_GENERAL_COMMANDS] = {
{ "eval", &LBCode::cmdEval },
{ "random", &LBCode::cmdRandom },
- { "stringLen", 0 },
- { "substring", 0 },
+ { "stringLen", &LBCode::cmdStringLen },
+ { "substring", &LBCode::cmdSubstring },
{ "max", 0 },
{ "min", 0 },
{ "abs", 0 },
@@ -861,6 +861,31 @@ void LBCode::cmdRandom(const Common::Array<LBValue> &params) {
_stack.push(_vm->_rnd->getRandomNumberRng(min, max));
}
+void LBCode::cmdStringLen(const Common::Array<LBValue> &params) {
+ if (params.size() != 1)
+ error("incorrect number of parameters (%d) to stringLen", params.size());
+
+ const Common::String &string = params[0].toString();
+ _stack.push(string.size());
+}
+
+void LBCode::cmdSubstring(const Common::Array<LBValue> &params) {
+ if (params.size() != 3)
+ error("incorrect number of parameters (%d) to substring", params.size());
+
+ const Common::String &string = params[0].toString();
+ uint begin = params[1].toInt();
+ uint end = params[2].toInt();
+ if (begin == 0)
+ error("invalid substring call (%d to %d)", begin, end);
+ if (begin > end || end > string.size()) {
+ _stack.push(Common::String());
+ return;
+ }
+ Common::String substring(string.c_str() + (begin - 1), end - begin + 1);
+ _stack.push(substring);
+}
+
void LBCode::cmdGetRect(const Common::Array<LBValue> &params) {
if (params.size() < 2) {
_stack.push(getRectFromParams(params));
diff --git a/engines/mohawk/livingbooks_code.h b/engines/mohawk/livingbooks_code.h
index 9c58ed7a46..79c9af94f7 100644
--- a/engines/mohawk/livingbooks_code.h
+++ b/engines/mohawk/livingbooks_code.h
@@ -222,6 +222,8 @@ public:
void cmdUnimplemented(const Common::Array<LBValue> &params);
void cmdEval(const Common::Array<LBValue> &params);
void cmdRandom(const Common::Array<LBValue> &params);
+ void cmdStringLen(const Common::Array<LBValue> &params);
+ void cmdSubstring(const Common::Array<LBValue> &params);
void cmdGetRect(const Common::Array<LBValue> &params);
void cmdTopLeft(const Common::Array<LBValue> &params);
void cmdBottomRight(const Common::Array<LBValue> &params);