summaryrefslogtreecommitdiff
path: root/src/script/api/script_text.cpp
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2011-12-21 14:55:28 +0000
committeryexo <yexo@openttd.org>2011-12-21 14:55:28 +0000
commit5988659eea20d3e84fdeadf448133e9b94e9630f (patch)
tree230c16eadf35e9868a3acf6d91b1b73ae412897d /src/script/api/script_text.cpp
parenta55478aaa6453d62f9708ee03393711b2d3120ee (diff)
downloadopenttd-5988659eea20d3e84fdeadf448133e9b94e9630f.tar.xz
(svn r23651) -Feature: [NoGo] GSText now accepts string arguments as parameters to the constructor
Diffstat (limited to 'src/script/api/script_text.cpp')
-rw-r--r--src/script/api/script_text.cpp30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/script/api/script_text.cpp b/src/script/api/script_text.cpp
index 10120bcde..e8803884b 100644
--- a/src/script/api/script_text.cpp
+++ b/src/script/api/script_text.cpp
@@ -15,10 +15,34 @@
#include "../squirrel.hpp"
#include "../../table/control_codes.h"
-ScriptText::ScriptText(StringID string) :
- ZeroedMemoryAllocator(),
- string(string)
+ScriptText::ScriptText(HSQUIRRELVM vm) :
+ ZeroedMemoryAllocator()
{
+ int nparam = sq_gettop(vm) - 1;
+ if (nparam < 1) {
+ throw sq_throwerror(vm, _SC("You need to pass at least a StringID to the constructor"));
+ }
+
+ /* First resolve the StringID. */
+ SQInteger sqstring;
+ if (SQ_FAILED(sq_getinteger(vm, 2, &sqstring))) {
+ throw sq_throwerror(vm, _SC("First argument must be a valid StringID"));
+ }
+ this->string = sqstring;
+
+ /* The rest of the parameters must be arguments. */
+ for (int i = 0; i < nparam - 1; i++) {
+ /* Push the parameter to the top of the stack. */
+ sq_push(vm, i + 3);
+
+ if (SQ_FAILED(this->_SetParam(i, vm))) {
+ this->~ScriptText();
+ throw sq_throwerror(vm, _SC("Invalid parameter"));
+ }
+
+ /* Pop the parameter again. */
+ sq_pop(vm, 1);
+ }
}
ScriptText::~ScriptText()