aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Sandulenko2016-07-09 17:11:33 +0200
committerEugene Sandulenko2016-08-03 23:40:36 +0200
commit8084989605853dd23e265a1f649e36611bdbfd99 (patch)
tree22d65d1f271190fe3354d6dc553b879e5f2e98a4
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
-rw-r--r--engines/director/director.cpp3
-rw-r--r--engines/director/lingo/lingo-builtins.cpp76
-rw-r--r--engines/director/lingo/lingo.cpp24
-rw-r--r--engines/director/lingo/lingo.h3
4 files changed, 82 insertions, 24 deletions
diff --git a/engines/director/director.cpp b/engines/director/director.cpp
index 2f77234dcd..97e7c70fda 100644
--- a/engines/director/director.cpp
+++ b/engines/director/director.cpp
@@ -132,6 +132,9 @@ Common::Error DirectorEngine::run() {
set z1 = z1 && \"woof\"\n\
put z\n\
put z1\n\
+ put chars(\"Macromedia\", 6, 6)\n\
+ put chars(\"Macromedia\", 6, 10)\n\
+ put chars(\"Macromedia\", 6, 15)\n\
", kMovieScript, 2);
_lingo->executeScript(kMovieScript, 2);
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);
}
+
}
diff --git a/engines/director/lingo/lingo.cpp b/engines/director/lingo/lingo.cpp
index fec6b645ea..9ec89ff0af 100644
--- a/engines/director/lingo/lingo.cpp
+++ b/engines/director/lingo/lingo.cpp
@@ -188,7 +188,7 @@ int Datum::toInt() {
type = INT;
break;
default:
- warning("Incorrect operation toInt() for type: %d", type);
+ warning("Incorrect operation toInt() for type: %s", type2str());
}
return u.i;
@@ -204,7 +204,7 @@ float Datum::toFloat() {
// no-op
break;
default:
- warning("Incorrect operation toFloat() for type: %d", type);
+ warning("Incorrect operation toFloat() for type: %s", type2str());
}
return u.f;
@@ -223,7 +223,7 @@ Common::String *Datum::toString() {
delete s;
s = u.s;
default:
- warning("Incorrect operation toInt() for type: %d", type);
+ warning("Incorrect operation toInt() for type: %s", type2str());
}
u.s = s;
@@ -232,4 +232,22 @@ Common::String *Datum::toString() {
return u.s;
}
+const char *Datum::type2str() {
+ static char res[20];
+
+ switch (type) {
+ case INT:
+ return "INT";
+ case FLOAT:
+ return "FLOAT";
+ case STRING:
+ return "STRING";
+ case CASTREF:
+ return "CASTREF";
+ default:
+ snprintf(res, 20, "-- (%d) --", type);
+ return res;
+ }
+}
+
} // End of namespace Director
diff --git a/engines/director/lingo/lingo.h b/engines/director/lingo/lingo.h
index eca9b4107c..162bb5f4e5 100644
--- a/engines/director/lingo/lingo.h
+++ b/engines/director/lingo/lingo.h
@@ -107,6 +107,8 @@ struct Datum { /* interpreter stack type */
float toFloat();
int toInt();
Common::String *toString();
+
+ const char *type2str();
};
struct Builtin {
@@ -216,6 +218,7 @@ public:
static void b_abs();
static void b_atan();
+ static void b_chars();
static void b_cos();
static void b_exp();
static void b_float();