summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2011-11-04 23:14:23 +0000
committeryexo <yexo@openttd.org>2011-11-04 23:14:23 +0000
commit02913f40b0ab1a7771e96e4c6af4ef15b6953cc7 (patch)
treea1fc33d33a53e45772823fe528d73d8194eb91ad
parent3e016e4254c6b8b558c50e7c66bc01ac6d118f4b (diff)
downloadopenttd-02913f40b0ab1a7771e96e4c6af4ef15b6953cc7.tar.xz
(svn r23117) -Fix: [NoAI] calling require() to include a file gave you 100.000 opcodes for free
-rw-r--r--bin/ai/regression/regression.txt12
-rw-r--r--src/script/squirrel.cpp4
2 files changed, 10 insertions, 6 deletions
diff --git a/bin/ai/regression/regression.txt b/bin/ai/regression/regression.txt
index 81b2699bf..3eb611eaf 100644
--- a/bin/ai/regression/regression.txt
+++ b/bin/ai/regression/regression.txt
@@ -8611,9 +8611,9 @@ ERROR: IsEnd() is invalid as Begin() is never called
GetNumWagons(): 3
GetLength(): 24
GetWagonEngineType(): 9
- GetWagonAge(): 0
+ GetWagonAge(): 1
GetWagonEngineType(): 27
- GetWagonAge(): 0
+ GetWagonAge(): 1
GetWagonEngineType(): 27
GetWagonAge(): 0
GetWagonEngineType(): 65535
@@ -8647,11 +8647,11 @@ ERROR: IsEnd() is invalid as Begin() is never called
14 => 1
12 => 1
Age ListDump:
+ 17 => 1
+ 16 => 1
14 => 1
13 => 1
12 => 1
- 17 => 0
- 16 => 0
MaxAge ListDump:
16 => 10980
14 => 10980
@@ -8659,9 +8659,9 @@ ERROR: IsEnd() is invalid as Begin() is never called
13 => 5490
12 => 5490
AgeLeft ListDump:
- 16 => 10980
+ 16 => 10979
14 => 10979
- 17 => 7320
+ 17 => 7319
13 => 5489
12 => 5489
CurrentSpeed ListDump:
diff --git a/src/script/squirrel.cpp b/src/script/squirrel.cpp
index b9151e727..890630eeb 100644
--- a/src/script/squirrel.cpp
+++ b/src/script/squirrel.cpp
@@ -481,15 +481,19 @@ static SQInteger _io_file_read(SQUserPointer file, SQUserPointer buf, SQInteger
/* Make sure we are always in the root-table */
if (in_root) sq_pushroottable(vm);
+ SQInteger ops_left = vm->_ops_till_suspend;
/* Load and run the script */
if (SQ_SUCCEEDED(LoadFile(vm, script, SQTrue))) {
sq_push(vm, -2);
if (SQ_SUCCEEDED(sq_call(vm, 1, SQFalse, SQTrue, 100000))) {
sq_pop(vm, 1);
+ /* After compiling the file we want to reset the amount of opcodes. */
+ vm->_ops_till_suspend = ops_left;
return true;
}
}
+ vm->_ops_till_suspend = ops_left;
DEBUG(misc, 0, "[squirrel] Failed to compile '%s'", script);
return false;
}