(svn r10554) [NoAI] -Codechange: allow classes with virtual functions to still export their enums. noai
authorrubidium
Fri, 13 Jul 2007 19:54:59 +0000
branchnoai
changeset 9653 50e2eb4abf46
parent 9652 c15bf5355b95
child 9654 b836eb5c521f
(svn r10554) [NoAI] -Codechange: allow classes with virtual functions to still export their enums.
src/ai/api/ai_pathfinder.hpp
src/ai/api/ai_pathfinder.hpp.sq
src/ai/api/ai_pathfinder_stupid.hpp
src/ai/api/squirrel_export.awk
--- a/src/ai/api/ai_pathfinder.hpp	Fri Jul 13 19:12:43 2007 +0000
+++ b/src/ai/api/ai_pathfinder.hpp	Fri Jul 13 19:54:59 2007 +0000
@@ -32,20 +32,23 @@
 	 * @param end a list of tiles where we can end.
 	 * @return internal structure about how to make the route, or NULL if no route was found.
 	 */
-	void *FindRoute(AITileList *start, AITileList *end) { return NULL; }
+	virtual void *FindRoute(AITileList *start, AITileList *end) = 0;
 
 	/**
 	 * Build the route as found by FindRoute.
 	 * @param result the result 'void *' from FindRoute.
 	 * @return true if the route was build, false if anything went wrong.
 	 */
-	bool BuildRoute(void *result) { return false; }
+	virtual bool BuildRoute(void *result) = 0;
 
 	/**
 	 * When you are done with the route result, we have to free it in order to avoid memleaks.
 	 * @note Always call this function on the result of FindRoute, even when you ran BuildRoute before!
 	 */
-	void FreeRoute(void *result) { }
+	virtual void FreeRoute(void *result) = 0;
+
+	/** Keep the compilers happy */
+	virtual ~AIPathFinder() {}
 };
 
 #endif /* AI_PATHFINDER_HPP */
--- a/src/ai/api/ai_pathfinder.hpp.sq	Fri Jul 13 19:12:43 2007 +0000
+++ b/src/ai/api/ai_pathfinder.hpp.sq	Fri Jul 13 19:54:59 2007 +0000
@@ -15,16 +15,11 @@
 void SQAIPathFinderRegister(Squirrel *engine) {
 	DefSQClass <AIPathFinder> SQAIPathFinder("AIPathFinder");
 	SQAIPathFinder.PreRegister(engine);
-	SQAIPathFinder.AddConstructor<void (AIPathFinder::*)(), 1>(engine, "x");
 
 	SQAIPathFinder.DefSQConst(engine, AIPathFinder::PATHFINDER_ROAD, "PATHFINDER_ROAD");
 	SQAIPathFinder.DefSQConst(engine, AIPathFinder::PATHFINDER_RAIL, "PATHFINDER_RAIL");
 
 	SQAIPathFinder.DefSQStaticMethod(engine, &AIPathFinder::GetClassName, "GetClassName", 1, "x");
 
-	SQAIPathFinder.DefSQMethod(engine, &AIPathFinder::FindRoute,  "FindRoute",  3, "xxx");
-	SQAIPathFinder.DefSQMethod(engine, &AIPathFinder::BuildRoute, "BuildRoute", 2, "xp");
-	SQAIPathFinder.DefSQMethod(engine, &AIPathFinder::FreeRoute,  "FreeRoute",  2, "xp");
-
 	SQAIPathFinder.PostRegister(engine);
 }
--- a/src/ai/api/ai_pathfinder_stupid.hpp	Fri Jul 13 19:12:43 2007 +0000
+++ b/src/ai/api/ai_pathfinder_stupid.hpp	Fri Jul 13 19:54:59 2007 +0000
@@ -27,6 +27,8 @@
 	bool BuildRoute(void *result);
 	void FreeRoute(void *result);
 
+	/** Keep the compilers happy */
+	virtual ~AIPathFinderStupid() {}
 private:
 	AIPathFinder::PathFinderType type;
 
--- a/src/ai/api/squirrel_export.awk	Fri Jul 13 19:12:43 2007 +0000
+++ b/src/ai/api/squirrel_export.awk	Fri Jul 13 19:54:59 2007 +0000
@@ -159,41 +159,43 @@
 
 	print "}; // namespace SQConvert"
 
+	print "";
+	# Then do the registration functions of the class. */
+	print "void SQ" cls "Register(Squirrel *engine) {"
+	print "	DefSQClass <" cls "> SQ" cls "(\"" cls "\");"
+	if (super_cls == "AIObject" || super_cls == "AIAbstractList::Valuator") {
+		print "	SQ" cls ".PreRegister(engine);"
+	} else {
+		print "	SQ" cls ".PreRegister(engine, \"" super_cls "\");"
+	}
 	if (virtual_class == "false") {
-		print "";
-		# Then do the registration functions of the class. */
-		print "void SQ" cls "Register(Squirrel *engine) {"
-		print "	DefSQClass <" cls "> SQ" cls "(\"" cls "\");"
-		if (super_cls == "AIObject" || super_cls == "AIAbstractList::Valuator") {
-			print "	SQ" cls ".PreRegister(engine);"
-		} else {
-			print "	SQ" cls ".PreRegister(engine, \"" super_cls "\");"
-		}
 		print "	SQ" cls ".AddConstructor<void (" cls "::*)(" cls_param[0] "), " cls_param[1]">(engine, \"" cls_param[2] "\");"
-		print ""
+	}
+	print ""
 
-		# Enum values
-		mlen = 0
-		for (i = 1; i <= enum_value_size; i++) {
-			if (mlen <= length(enum_value[i])) mlen = length(enum_value[i])
-		}
-		for (i = 1; i <= enum_value_size; i++) {
-			print "	SQ" cls ".DefSQConst(engine, " cls "::" enum_value[i] ", " substr(spaces, 1, mlen - length(enum_value[i])) "\""  enum_value[i] "\");"
-			delete enum_value[i]
-		}
-		if (enum_value_size != 0) print ""
+	# Enum values
+	mlen = 0
+	for (i = 1; i <= enum_value_size; i++) {
+		if (mlen <= length(enum_value[i])) mlen = length(enum_value[i])
+	}
+	for (i = 1; i <= enum_value_size; i++) {
+		print "	SQ" cls ".DefSQConst(engine, " cls "::" enum_value[i] ", " substr(spaces, 1, mlen - length(enum_value[i])) "\""  enum_value[i] "\");"
+		delete enum_value[i]
+	}
+	if (enum_value_size != 0) print ""
 
-		# Static methods
-		mlen = 0
-		for (i = 1; i <= static_method_size; i++) {
-			if (mlen <= length(static_methods[i, 0])) mlen = length(static_methods[i, 0])
-		}
-		for (i = 1; i <= static_method_size; i++) {
-			print "	SQ" cls ".DefSQStaticMethod(engine, &" cls "::" static_methods[i, 0] ", " substr(spaces, 1, mlen - length(static_methods[i, 0])) "\""  static_methods[i, 0] "\", " substr(spaces, 1, mlen - length(static_methods[i, 0])) "" static_methods[i, 1] ", \"" static_methods[i, 2] "\");"
-			delete static_methods[i]
-		}
-		if (static_method_size != 0) print ""
+	# Static methods
+	mlen = 0
+	for (i = 1; i <= static_method_size; i++) {
+		if (mlen <= length(static_methods[i, 0])) mlen = length(static_methods[i, 0])
+	}
+	for (i = 1; i <= static_method_size; i++) {
+		print "	SQ" cls ".DefSQStaticMethod(engine, &" cls "::" static_methods[i, 0] ", " substr(spaces, 1, mlen - length(static_methods[i, 0])) "\""  static_methods[i, 0] "\", " substr(spaces, 1, mlen - length(static_methods[i, 0])) "" static_methods[i, 1] ", \"" static_methods[i, 2] "\");"
+		delete static_methods[i]
+	}
+	if (static_method_size != 0) print ""
 
+	if (virtual_class == "false") {
 		# Non-static methods
 		mlen = 0
 		for (i = 1; i <= method_size; i++) {
@@ -204,10 +206,9 @@
 			delete methods[i]
 		}
 		if (method_size != 0) print ""
-
-		print "	SQ" cls ".PostRegister(engine);"
-		print "}"
 	}
+	print "	SQ" cls ".PostRegister(engine);"
+	print "}"
 
 	enum_size = 0
 	enum_value_size = 0
@@ -235,6 +236,7 @@
 # Add a method to the list
 /^.*\(.*\).*$/ {
 	if (cls_level != 1) next
+	if (match($0, "~")) next
 
 	is_static = match($0, "static")
 	if (match($0, "virtual")) {