src/ai/squirrel/engine.cpp
branchnoai
changeset 9404 ef9e171617a3
parent 9396 a05857491d2d
--- a/src/ai/squirrel/engine.cpp	Thu Mar 15 13:28:11 2007 +0000
+++ b/src/ai/squirrel/engine.cpp	Thu Mar 15 13:36:45 2007 +0000
@@ -94,7 +94,22 @@
 	sq_createslot(vm, -3);
 }
 
-void SquirrelEngine::CallMethod(HSQOBJECT instance, const char *method_name)
+bool SquirrelEngine::MethodExists(HSQOBJECT instance, const char *method_name)
+{
+	int top = sq_gettop(this->vm);
+	/* Go to the instance-root */
+	sq_pushobject(this->vm, instance);
+	/* Find the function-name inside the script */
+	sq_pushstring(this->vm, method_name, -1);
+	if (SQ_FAILED(sq_get(this->vm, -2))) {
+		sq_settop(this->vm, top);
+		return false;
+	}
+	sq_settop(this->vm, top);
+	return true;
+}
+
+void SquirrelEngine::CallMethod(HSQOBJECT instance, const char *method_name, HSQOBJECT *ret)
 {
 	/* Store the current top */
 	int top = sq_gettop(this->vm);
@@ -109,7 +124,8 @@
 	}
 	/* Call the method */
 	sq_pushobject(this->vm, instance);
-	sq_call(this->vm, 1, 0, 0);
+	sq_call(this->vm, 1, ret == NULL ? SQFalse : SQTrue, SQFalse);
+	if (ret != NULL) sq_getstackobj(vm, -1, ret);
 	/* Reset the top */
 	sq_settop(this->vm, top);
 }