MOHAWK: Implement stringLen and substring LBCode functions.

This commit is contained in:
Alyssa Milburn 2011-07-07 16:20:01 +02:00
parent 33a85af915
commit e4fc8e85ed
2 changed files with 29 additions and 2 deletions

View File

@ -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));

View File

@ -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);