MOHAWK: Implement stringLen and substring LBCode functions.
This commit is contained in:
parent
33a85af915
commit
e4fc8e85ed
2 changed files with 29 additions and 2 deletions
|
@ -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> ¶ms) {
|
|||
_stack.push(_vm->_rnd->getRandomNumberRng(min, max));
|
||||
}
|
||||
|
||||
void LBCode::cmdStringLen(const Common::Array<LBValue> ¶ms) {
|
||||
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> ¶ms) {
|
||||
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> ¶ms) {
|
||||
if (params.size() < 2) {
|
||||
_stack.push(getRectFromParams(params));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue