--- a/src/ai/squirrel/squirrel.cpp Wed Mar 14 10:30:34 2007 +0000
+++ b/src/ai/squirrel/squirrel.cpp Wed Mar 14 10:39:46 2007 +0000
@@ -66,18 +66,20 @@
sq_getstackobj(vm, 1, &object);
SQ_instance = object._unVal.pUserPointer;
- /* We stored the real 'this' in _main_ptr */
- sq_pushroottable(vm);
- sq_pushstring(vm, "_main_ptr", -1);
- sq_get(vm, -2);
- sq_getuserpointer(vm, -1, (SQUserPointer *)&self);
-
- /* Now store it in this instance */
+ /* Find the 'this' pointer and store it inside the class */
+ self = (Squirrel *)sq_getforeignptr(vm);
+ if (self == NULL) {
+ DEBUG(ai, 0, "[squirrel] Please only make one instance of AIController!");
+ return SQ_ERROR;
+ }
sq_setinstanceup(vm, 1, self);
sq_setreleasehook(vm, 1, &Squirrel::SQDestructor);
/* Keep track of the internal Squirrel instance */
self->SQ_instance = SQ_instance;
+ /* Make sure we only register one AI in this script */
+ sq_setforeignptr(vm, NULL);
+
return 0;
}
@@ -109,11 +111,8 @@
{
SQInteger top = sq_gettop(this->vm);
- /* Store 'this' in _main_ptr so we can find it back later on */
- sq_pushroottable(this->vm);
- sq_pushstring(this->vm, "_main_ptr", -1);
- sq_pushuserpointer(this->vm, this);
- sq_createslot(this->vm, -3);
+ /* Store 'this' so we can find it back later on */
+ sq_setforeignptr(this->vm, this);
/* Create AIController class (the 'main' of it all) */
sq_pushroottable(this->vm);