summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzuu <zuu@openttd.org>2013-05-29 19:31:58 +0000
committerzuu <zuu@openttd.org>2013-05-29 19:31:58 +0000
commita58427115cbf7569fad746c588cd93a9bd14b57f (patch)
tree808032e98992efdca906245fab93f5cdb555eda1
parent2547523c0f5a3ab09911f465b60721651d588eac (diff)
downloadopenttd-a58427115cbf7569fad746c588cd93a9bd14b57f.tar.xz
(svn r25305) -Fix [FS#5561]: Game Script APIs that execute a DoCommand were returning the same result as in TestMode during world generation
-rw-r--r--src/script/api/script_object.cpp7
-rw-r--r--src/script/squirrel.cpp12
2 files changed, 14 insertions, 5 deletions
diff --git a/src/script/api/script_object.cpp b/src/script/api/script_object.cpp
index 7da23d6f7..2852c4ae9 100644
--- a/src/script/api/script_object.cpp
+++ b/src/script/api/script_object.cpp
@@ -300,7 +300,12 @@ ScriptObject::ActiveInstance::~ActiveInstance()
if (_generating_world) {
IncreaseDoCommandCosts(res.GetCost());
- if (callback != NULL) callback(GetActiveInstance());
+ if (callback != NULL) {
+ /* Insert return value into to stack and throw a control code that
+ * the return value in the stack should be used. */
+ callback(GetActiveInstance());
+ throw SQInteger(1);
+ }
return true;
} else if (_networking) {
/* Suspend the script till the command is really executed. */
diff --git a/src/script/squirrel.cpp b/src/script/squirrel.cpp
index 4584b9d6c..ed87d487c 100644
--- a/src/script/squirrel.cpp
+++ b/src/script/squirrel.cpp
@@ -541,15 +541,19 @@ Squirrel::~Squirrel()
void Squirrel::InsertResult(bool result)
{
sq_pushbool(this->vm, result);
- vm->GetAt(vm->_stackbase + vm->_suspended_target) = vm->GetUp(-1);
- vm->Pop();
+ if (this->IsSuspended()) { // Called before resuming a suspended script?
+ vm->GetAt(vm->_stackbase + vm->_suspended_target) = vm->GetUp(-1);
+ vm->Pop();
+ }
}
void Squirrel::InsertResult(int result)
{
sq_pushinteger(this->vm, result);
- vm->GetAt(vm->_stackbase + vm->_suspended_target) = vm->GetUp(-1);
- vm->Pop();
+ if (this->IsSuspended()) { // Called before resuming a suspended script?
+ vm->GetAt(vm->_stackbase + vm->_suspended_target) = vm->GetUp(-1);
+ vm->Pop();
+ }
}
/* static */ void Squirrel::DecreaseOps(HSQUIRRELVM vm, int ops)