(svn r13496) [NoAI] -Fix: if a library depends on an other library, the import became globally known, which defeats the idea of imports. They are now restricted to their scope, and 'import' returns the class of import (if any) noai
authortruebrain
Thu, 12 Jun 2008 19:47:02 +0000
branchnoai
changeset 10942 cd3f2d07199f
parent 10939 e7693a7bb280
child 10943 5f5a5dd407d8
(svn r13496) [NoAI] -Fix: if a library depends on an other library, the import became globally known, which defeats the idea of imports. They are now restricted to their scope, and 'import' returns the class of import (if any)
bin/ai/library/graph/aystar/main.nut
src/ai/ai_info.cpp
src/ai/ai_squirrel.cpp
--- a/bin/ai/library/graph/aystar/main.nut	Thu Jun 12 18:14:06 2008 +0000
+++ b/bin/ai/library/graph/aystar/main.nut	Thu Jun 12 19:47:02 2008 +0000
@@ -1,14 +1,12 @@
 /* $Id$ */
 
-/* We need a Queue */
-import("queue.binary_heap", "Queue", 1);
-
 /**
  * An AyStar implementation.
  *  It solves graphs by finding the fastest route from one point to the other.
  */
 class AyStar
 {
+	_queue_class = import("queue.binary_heap", "", 1);
 	_cost_callback = null;
 	_estimate_callback = null;
 	_neighbours_callback = null;
@@ -85,7 +83,7 @@
 	if (typeof(sources) != "array" || sources.len() == 0) throw("sources has be a non-empty array.");
 	if (typeof(goals) != "array" || goals.len() == 0) throw("goals has be a non-empty array.");
 
-	this._open = Queue();
+	this._open = this._queue_class();
 	this._closed = AIList();
 
 	foreach (node in sources) {
--- a/src/ai/ai_info.cpp	Thu Jun 12 18:14:06 2008 +0000
+++ b/src/ai/ai_info.cpp	Thu Jun 12 19:47:02 2008 +0000
@@ -159,5 +159,5 @@
 	int version = GetParam(SQConvert::ForceType<int>(), vm, 4, &ptr);
 
 	if (!AI_ImportLibrary(library, class_name, version, vm)) return -1;
-	return 0;
+	return 1;
 }
--- 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;
 }