From 3949050714463bf13ffb6da231019de6db22a8e5 Mon Sep 17 00:00:00 2001 From: yexo Date: Tue, 21 Apr 2009 19:13:32 +0000 Subject: (svn r16113) -Feature [NoAI]: Add UseAsRandomAI as function in info.nut. When an AI returns false, it'll never be chosen as random AI. --- src/script/squirrel.cpp | 9 +++++++++ src/script/squirrel.hpp | 6 ++++++ 2 files changed, 15 insertions(+) (limited to 'src/script') diff --git a/src/script/squirrel.cpp b/src/script/squirrel.cpp index a62c83418..f31b813da 100644 --- a/src/script/squirrel.cpp +++ b/src/script/squirrel.cpp @@ -234,6 +234,15 @@ bool Squirrel::CallIntegerMethod(HSQOBJECT instance, const char *method_name, in return true; } +bool Squirrel::CallBoolMethod(HSQOBJECT instance, const char *method_name, bool *res, int suspend) +{ + HSQOBJECT ret; + if (!this->CallMethod(instance, method_name, &ret, suspend)) return false; + if (ret._type != OT_BOOL) return false; + *res = ObjectToBool(&ret); + return true; +} + /* static */ bool Squirrel::CreateClassInstanceVM(HSQUIRRELVM vm, const char *class_name, void *real_instance, HSQOBJECT *instance, SQRELEASEHOOK release_hook) { int oldtop = sq_gettop(vm); diff --git a/src/script/squirrel.hpp b/src/script/squirrel.hpp index 31b36f968..ee597f87a 100644 --- a/src/script/squirrel.hpp +++ b/src/script/squirrel.hpp @@ -116,6 +116,7 @@ public: bool CallMethod(HSQOBJECT instance, const char *method_name, int suspend = -1) { return this->CallMethod(instance, method_name, NULL, suspend); } bool CallStringMethodStrdup(HSQOBJECT instance, const char *method_name, const char **res, int suspend = -1); bool CallIntegerMethod(HSQOBJECT instance, const char *method_name, int *res, int suspend = -1); + bool CallBoolMethod(HSQOBJECT instance, const char *method_name, bool *res, int suspend = -1); /** * Check if a method exists in an instance. @@ -161,6 +162,11 @@ public: */ static int ObjectToInteger(HSQOBJECT *ptr) { return sq_objtointeger(ptr); } + /** + * Convert a Squirrel-object to a bool. + */ + static bool ObjectToBool(HSQOBJECT *ptr) { return sq_objtobool(ptr) == 1; } + /** * Sets a pointer in the VM that is reachable from where ever you are in SQ. * Useful to keep track of the main instance. -- cgit v1.2.3-70-g09d2