aboutsummaryrefslogtreecommitdiff
path: root/engines/director/lingo/lingo-builtins.cpp
diff options
context:
space:
mode:
authorEugene Sandulenko2016-07-09 17:11:33 +0200
committerEugene Sandulenko2016-08-03 23:40:36 +0200
commit8084989605853dd23e265a1f649e36611bdbfd99 (patch)
tree22d65d1f271190fe3354d6dc553b879e5f2e98a4 /engines/director/lingo/lingo-builtins.cpp
parentbb8fd6a8990f8364fc6411ba98ec4716429c98d8 (diff)
downloadscummvm-rg350-8084989605853dd23e265a1f649e36611bdbfd99.tar.gz
scummvm-rg350-8084989605853dd23e265a1f649e36611bdbfd99.tar.bz2
scummvm-rg350-8084989605853dd23e265a1f649e36611bdbfd99.zip
DIRECTOR: Lingo: Implemented chars() function and added more debug for type printing
Diffstat (limited to 'engines/director/lingo/lingo-builtins.cpp')
-rw-r--r--engines/director/lingo/lingo-builtins.cpp76
1 files changed, 55 insertions, 21 deletions
diff --git a/engines/director/lingo/lingo-builtins.cpp b/engines/director/lingo/lingo-builtins.cpp
index 696aca1cfa..873e844228 100644
--- a/engines/director/lingo/lingo-builtins.cpp
+++ b/engines/director/lingo/lingo-builtins.cpp
@@ -29,21 +29,24 @@ static struct BuiltinProto {
void (*func)(void);
int nparams;
} builtins[] = {
+ // Math
{ "abs", Lingo::b_abs, 1},
{ "atan", Lingo::b_atan, 1},
{ "cos", Lingo::b_cos, 1},
{ "exp", Lingo::b_exp, 1},
{ "float", Lingo::b_float, 1},
{ "integer",Lingo::b_integer, 1},
- { "length", Lingo::b_length, 1},
{ "log", Lingo::b_log, 1},
{ "pi", Lingo::b_pi, 0},
{ "power", Lingo::b_power, 2},
{ "random", Lingo::b_random, 1},
{ "sin", Lingo::b_sin, 1},
{ "sqrt", Lingo::b_sqrt, 1},
- { "string", Lingo::b_string, 1},
{ "tan", Lingo::b_tan, 1},
+ // String
+ { "chars", Lingo::b_chars, 3},
+ { "length", Lingo::b_length, 1},
+ { "string", Lingo::b_string, 1},
{ 0, 0, 0 }
};
@@ -53,6 +56,9 @@ void Lingo::initBuiltIns() {
}
}
+///////////////////
+// Math
+///////////////////
void Lingo::b_abs() {
Datum d = g_lingo->pop();
@@ -98,20 +104,6 @@ void Lingo::b_integer() {
g_lingo->push(d);
}
-void Lingo::b_length() {
- Datum d = g_lingo->pop();
-
- if (d.type != STRING)
- error("Incorrect type for 'length' function: %d", d.type);
-
- int len = strlen(d.u.s->c_str());
- delete d.u.s;
-
- d.u.i = len;
- d.type = INT;
- g_lingo->push(d);
-}
-
void Lingo::b_log() {
Datum d = g_lingo->pop();
d.toFloat();
@@ -161,17 +153,59 @@ void Lingo::b_sqrt() {
g_lingo->push(d);
}
-void Lingo::b_string() {
+void Lingo::b_tan() {
Datum d = g_lingo->pop();
- d.toString();
+ d.toFloat();
+ d.u.f = tan(d.u.f);
g_lingo->push(d);
}
-void Lingo::b_tan() {
+///////////////////
+// String
+///////////////////
+void Lingo::b_chars() {
+ Datum to = g_lingo->pop();
+ Datum from = g_lingo->pop();
+ Datum s = g_lingo->pop();
+
+ if (s.type != STRING)
+ error("Incorrect type for 'chars' function: %s", s.type2str());
+
+ to.toInt();
+ from.toInt();
+
+ int len = strlen(s.u.s->c_str());
+ int f = MAX(0, MIN(len, from.u.i - 1));
+ int t = MAX(0, MIN(len, to.u.i));
+
+ Common::String *res = new Common::String(&(s.u.s->c_str()[f]), &(s.u.s->c_str()[t]));
+
+ delete s.u.s;
+
+ s.u.s = res;
+ s.type = STRING;
+ g_lingo->push(s);
+}
+
+void Lingo::b_length() {
Datum d = g_lingo->pop();
- d.toFloat();
- d.u.f = tan(d.u.f);
+
+ if (d.type != STRING)
+ error("Incorrect type for 'length' function: %s", d.type2str());
+
+ int len = strlen(d.u.s->c_str());
+ delete d.u.s;
+
+ d.u.i = len;
+ d.type = INT;
+ g_lingo->push(d);
+}
+
+void Lingo::b_string() {
+ Datum d = g_lingo->pop();
+ d.toString();
g_lingo->push(d);
}
+
}