(svn r9171) [NoAI] -Fix: call GameLoop() of the instance directly noai
authortruelight
Wed, 14 Mar 2007 11:20:56 +0000
branchnoai
changeset 9381 df270ca8eec8
parent 9380 f4c7eb98b43d
child 9382 509365aac243
(svn r9171) [NoAI] -Fix: call GameLoop() of the instance directly
bin/ai/SQNoAI/main.sq
src/ai/squirrel/squirrel.cpp
src/ai/squirrel/squirrel.hpp
--- a/bin/ai/SQNoAI/main.sq	Wed Mar 14 11:14:57 2007 +0000
+++ b/bin/ai/SQNoAI/main.sq	Wed Mar 14 11:20:56 2007 +0000
@@ -12,9 +12,5 @@
 /* Initialize the AI in the global space */
 ai <- SQNoAI();
 print("I am " + ai);
-
-/* Loop the GameLoop to our own class */
-function GameLoop() { ai.GameLoop(); }
-
 print("Called init");
 
--- a/src/ai/squirrel/squirrel.cpp	Wed Mar 14 11:14:57 2007 +0000
+++ b/src/ai/squirrel/squirrel.cpp	Wed Mar 14 11:20:56 2007 +0000
@@ -58,13 +58,11 @@
 SQInteger Squirrel::SQConstructor(HSQUIRRELVM vm)
 {
 	Squirrel *self = NULL;
-	HSQOBJECT object;
-	SQUserPointer SQ_instance;
+	HSQOBJECT SQ_instance;
 
 	/* Get the instance pointer */
 	sq_getclass(vm, 1);
-	sq_getstackobj(vm, 1, &object);
-	SQ_instance = object._unVal.pUserPointer;
+	sq_getstackobj(vm, 1, &SQ_instance);
 
 	/* Find the 'this' pointer and store it inside the class */
 	self = (Squirrel *)sq_getforeignptr(vm);
@@ -175,8 +173,8 @@
 {
 	/* Store the current top */
 	int top = sq_gettop(this->vm);
-	/* Go back to root-table */
-	sq_pushroottable(this->vm);
+	/* Go to the instance-root */
+	sq_pushobject(this->vm, this->SQ_instance);
 	/* Find the function-name inside the script */
 	sq_pushstring(this->vm, "GameLoop", -1);
 	if (!SQ_SUCCEEDED(sq_get(this->vm, -2))) {
@@ -184,8 +182,8 @@
 		sq_settop(this->vm, top);
 		return;
 	}
-	/* Call the function */
-	sq_pushroottable(this->vm);
+	/* Call the method */
+	sq_pushobject(this->vm, this->SQ_instance);
 	sq_call(this->vm, 1, 0, 0);
 	/* Reset the top */
 	sq_settop(this->vm, top);
--- a/src/ai/squirrel/squirrel.hpp	Wed Mar 14 11:14:57 2007 +0000
+++ b/src/ai/squirrel/squirrel.hpp	Wed Mar 14 11:20:56 2007 +0000
@@ -12,7 +12,7 @@
 class Squirrel: public AIController {
 private:
 	HSQUIRRELVM vm;  ///< The Virtual Machine for squirrel
-	SQUserPointer SQ_instance; ///< The internal instance of squirrel
+	HSQOBJECT SQ_instance; ///< The internal instance of squirrel
 
 	/**
 	 * Add a single method to a class (in creation) in Squirrel.