src/ai/ai_squirrel.cpp
branchnoai
changeset 10942 cd3f2d07199f
parent 10900 90b1d2fbb899
child 10958 65088d587094
--- a/src/ai/ai_squirrel.cpp	Thu Jun 12 18:14:06 2008 +0000
+++ b/src/ai/ai_squirrel.cpp	Thu Jun 12 19:47:02 2008 +0000
@@ -185,6 +185,10 @@
 	char fake_class[1024];
 	snprintf(fake_class, sizeof(fake_class), "_internalNA%d", ++this->library_instance_count);
 
+	/* Get the current table/class we belong to */
+	HSQOBJECT parent;
+	sq_getstackobj(vm, 1, &parent);
+
 	/* Load the library in a 'fake' namespace, so we can link it to the name the user requested */
 	sq_pushroottable(vm);
 	sq_pushstring(vm, OTTD2FS(fake_class), -1);
@@ -218,14 +222,20 @@
 	sq_getstackobj(vm, -1, &obj);
 	sq_pop(vm, 3);
 
+	if (StrEmpty(class_name)) {
+		sq_pushobject(vm, obj);
+		return true;
+	}
+
 	/* Now link the name the user wanted to our 'fake' class */
-	sq_pushroottable(vm);
+	sq_pushobject(vm, parent);
 	sq_pushstring(vm, OTTD2FS(class_name), -1);
 	sq_pushobject(vm, obj);
 	sq_newclass(vm, SQTrue);
 	sq_newslot(vm, -3, SQFalse);
 	sq_pop(vm, 1);
 
+	sq_pushobject(vm, obj);
 	return true;
 }