(svn r13438) [NoAI] -Fix: sq_pop when needed, to make sure the stack keeps as clean as possible noai
authortruebrain
Tue, 10 Jun 2008 09:56:56 +0000
branchnoai
changeset 10887 5c81038449f2
parent 10885 415791bee9d7
child 10888 8a74bb2691b0
(svn r13438) [NoAI] -Fix: sq_pop when needed, to make sure the stack keeps as clean as possible
src/squirrel.cpp
src/squirrel.hpp
--- a/src/squirrel.cpp	Mon Jun 09 21:24:10 2008 +0000
+++ b/src/squirrel.cpp	Tue Jun 10 09:56:56 2008 +0000
@@ -149,6 +149,7 @@
 void Squirrel::AddClassEnd()
 {
 	sq_newslot(vm, -3, SQFalse);
+	sq_pop(vm, 1);
 }
 
 bool Squirrel::MethodExists(HSQOBJECT instance, const char *method_name)
@@ -365,16 +366,16 @@
 	return sq_throwerror(vm, _SC("cannot open the file"));
 }
 
-/* static */ bool Squirrel::LoadScript(HSQUIRRELVM vm, const char *script)
+/* static */ bool Squirrel::LoadScript(HSQUIRRELVM vm, const char *script, bool in_root)
 {
 	/* Make sure we are always in the root-table */
-	sq_pushroottable(vm);
+	if (in_root) sq_pushroottable(vm);
 
 	/* 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))) {
-			sq_remove(vm, -1);
+			sq_pop(vm, 1);
 			return true;
 		}
 	}
--- a/src/squirrel.hpp	Mon Jun 09 21:24:10 2008 +0000
+++ b/src/squirrel.hpp	Tue Jun 10 09:56:56 2008 +0000
@@ -49,7 +49,7 @@
 	 * @return False if loading failed.
 	 */
 	bool LoadScript(const char *script);
-	static bool LoadScript(HSQUIRRELVM vm, const char *script);
+	static bool LoadScript(HSQUIRRELVM vm, const char *script, bool in_root = true);
 
 	/**
 	 * Load a file to a given VM.