(svn r9446) [NoAI] -Add: simple script to make changing/adding classes to export a little simpler. noai
authorrubidium
Sun, 25 Mar 2007 14:19:59 +0000
branchnoai
changeset 9526 a4ad60ba03be
parent 9525 1d6c509b56ee
child 9527 f709c97a5d9f
(svn r9446) [NoAI] -Add: simple script to make changing/adding classes to export a little simpler.
src/ai/api/ai_accounting.hpp
src/ai/api/ai_base.hpp
src/ai/api/ai_cargo.hpp
src/ai/api/ai_company.hpp
src/ai/api/ai_execmode.hpp
src/ai/api/ai_industry.hpp
src/ai/api/ai_map.hpp
src/ai/api/ai_order.hpp
src/ai/api/ai_road.hpp
src/ai/api/ai_settings.hpp
src/ai/api/ai_sign.hpp
src/ai/api/ai_testmode.hpp
src/ai/api/ai_town.hpp
src/ai/api/ai_transactionmode.hpp
src/ai/api/ai_vehicle.hpp
src/ai/api/squirrel_export.awk
src/ai/api/squirrel_export.sh
--- a/src/ai/api/ai_accounting.hpp	Sun Mar 25 13:55:31 2007 +0000
+++ b/src/ai/api/ai_accounting.hpp	Sun Mar 25 14:19:59 2007 +0000
@@ -56,8 +56,10 @@
 	DefSQClass <AIAccounting> SQAIAccounting("AIAccounting");
 	SQAIAccounting.PreRegister(engine);
 	SQAIAccounting.AddConstructor(engine);
+
 	SQAIAccounting.DefSQFunction(engine, &AIAccounting::GetCosts,   "GetCosts");
 	SQAIAccounting.DefSQFunction(engine, &AIAccounting::ResetCosts, "ResetCosts");
+
 	SQAIAccounting.PostRegister(engine);
 }
 #endif /* DEFINE_SQUIRREL_CLASS */
--- a/src/ai/api/ai_base.hpp	Sun Mar 25 13:55:31 2007 +0000
+++ b/src/ai/api/ai_base.hpp	Sun Mar 25 14:19:59 2007 +0000
@@ -51,9 +51,11 @@
 	DefSQClass <AIBase> SQAIBase("AIBase");
 	SQAIBase.PreRegister(engine);
 	SQAIBase.AddConstructor(engine);
+
 	SQAIBase.DefSQFunction(engine, &AIBase::Rand,      "Rand");
 	SQAIBase.DefSQFunction(engine, &AIBase::RandRange, "RandRange");
 	SQAIBase.DefSQFunction(engine, &AIBase::Chance,    "Chance");
+
 	SQAIBase.PostRegister(engine);
 }
 #endif /* DEFINE_SQUIRREL_CLASS */
--- a/src/ai/api/ai_cargo.hpp	Sun Mar 25 13:55:31 2007 +0000
+++ b/src/ai/api/ai_cargo.hpp	Sun Mar 25 14:19:59 2007 +0000
@@ -55,10 +55,12 @@
 	DefSQClass <AICargo> SQAICargo("AICargo");
 	SQAICargo.PreRegister(engine);
 	SQAICargo.AddConstructor(engine);
+
 	SQAICargo.DefSQFunction(engine, &AICargo::IsValidCargo,   "IsValidCargo");
 	SQAICargo.DefSQFunction(engine, &AICargo::GetCargoLabel,  "GetCargoLabel");
 	SQAICargo.DefSQFunction(engine, &AICargo::IsFreight,      "IsFreight");
 	SQAICargo.DefSQFunction(engine, &AICargo::GetCargoIncome, "GetCargoIncome");
+
 	SQAICargo.PostRegister(engine);
 }
 #endif /* DEFINE_SQUIRREL_CLASS */
--- a/src/ai/api/ai_company.hpp	Sun Mar 25 13:55:31 2007 +0000
+++ b/src/ai/api/ai_company.hpp	Sun Mar 25 14:19:59 2007 +0000
@@ -84,6 +84,7 @@
 	DefSQClass <AICompany> SQAICompany("AICompany");
 	SQAICompany.PreRegister(engine);
 	SQAICompany.AddConstructor(engine);
+
 	SQAICompany.DefSQFunction(engine, &AICompany::SetCompanyName,   "SetCompanyName");
 	SQAICompany.DefSQFunction(engine, &AICompany::GetCompanyName,   "GetCompanyName");
 	SQAICompany.DefSQFunction(engine, &AICompany::GetCompanyValue,  "GetCompanyValue");
@@ -92,6 +93,7 @@
 	SQAICompany.DefSQFunction(engine, &AICompany::GetMaxLoanAmount, "GetMaxLoanAmount");
 	SQAICompany.DefSQFunction(engine, &AICompany::GetLoanInterval,  "GetLoanInterval");
 	SQAICompany.DefSQFunction(engine, &AICompany::SetLoanAmount,    "SetLoanAmount");
+
 	SQAICompany.PostRegister(engine);
 }
 #endif /* DEFINE_SQUIRREL_CLASS */
--- a/src/ai/api/ai_execmode.hpp	Sun Mar 25 13:55:31 2007 +0000
+++ b/src/ai/api/ai_execmode.hpp	Sun Mar 25 14:19:59 2007 +0000
@@ -50,6 +50,8 @@
 	DefSQClass <AIExecMode> SQAIExecMode("AIExecMode");
 	SQAIExecMode.PreRegister(engine);
 	SQAIExecMode.AddConstructor(engine);
+
+
 	SQAIExecMode.PostRegister(engine);
 }
 #endif /* DEFINE_SQUIRREL_CLASS */
--- a/src/ai/api/ai_industry.hpp	Sun Mar 25 13:55:31 2007 +0000
+++ b/src/ai/api/ai_industry.hpp	Sun Mar 25 14:19:59 2007 +0000
@@ -64,11 +64,13 @@
 	DefSQClass <AIIndustry> SQAIIndustry("AIIndustry");
 	SQAIIndustry.PreRegister(engine);
 	SQAIIndustry.AddConstructor(engine);
+
 	SQAIIndustry.DefSQFunction(engine, &AIIndustry::GetMaxIndustryID, "GetMaxIndustryID");
 	SQAIIndustry.DefSQFunction(engine, &AIIndustry::GetIndustryCount, "GetIndustryCount");
 	SQAIIndustry.DefSQFunction(engine, &AIIndustry::IsValidIndustry,  "IsValidIndustry");
 	SQAIIndustry.DefSQFunction(engine, &AIIndustry::GetName,          "GetName");
 	SQAIIndustry.DefSQFunction(engine, &AIIndustry::GetLocation,      "GetLocation");
+
 	SQAIIndustry.PostRegister(engine);
 }
 #endif /* DEFINE_SQUIRREL_CLASS */
--- a/src/ai/api/ai_map.hpp	Sun Mar 25 13:55:31 2007 +0000
+++ b/src/ai/api/ai_map.hpp	Sun Mar 25 14:19:59 2007 +0000
@@ -130,6 +130,7 @@
 	DefSQClass <AIMap> SQAIMap("AIMap");
 	SQAIMap.PreRegister(engine);
 	SQAIMap.AddConstructor(engine);
+
 	SQAIMap.DefSQFunction(engine, &AIMap::IsValidTile,       "IsValidTile");
 	SQAIMap.DefSQFunction(engine, &AIMap::GetMapSize,        "GetMapSize");
 	SQAIMap.DefSQFunction(engine, &AIMap::GetMapSizeX,       "GetMapSizeX");
@@ -142,6 +143,7 @@
 	SQAIMap.DefSQFunction(engine, &AIMap::DistanceSquare,    "DistanceSquare");
 	SQAIMap.DefSQFunction(engine, &AIMap::DistanceFromEdge,  "DistanceFromEdge");
 	SQAIMap.DefSQFunction(engine, &AIMap::DemolishTile,      "DemolishTile");
+
 	SQAIMap.PostRegister(engine);
 }
 #endif /* DEFINE_SQUIRREL_CLASS */
--- a/src/ai/api/ai_order.hpp	Sun Mar 25 13:55:31 2007 +0000
+++ b/src/ai/api/ai_order.hpp	Sun Mar 25 14:19:59 2007 +0000
@@ -170,26 +170,27 @@
 	SQAIOrder.PreRegister(engine);
 	SQAIOrder.AddConstructor(engine);
 
-	SQAIOrder.DefSQConst(engine, AIOrder::AIOF_NONE,               "AIOF_NONE");
-	SQAIOrder.DefSQConst(engine, AIOrder::AIOF_TRANSFER,           "AIOF_TRANSFER");
-	SQAIOrder.DefSQConst(engine, AIOrder::AIOF_UNLOAD,             "AIOF_UNLOAD");
-	SQAIOrder.DefSQConst(engine, AIOrder::AIOF_FULL_LOAD,          "AIOF_FULL_LOAD");
-	SQAIOrder.DefSQConst(engine, AIOrder::AIOF_SERVICE_IF_NEEDED,  "AIOF_SERVICE_IF_NEEDED");
-	SQAIOrder.DefSQConst(engine, AIOrder::AIOF_NON_STOP,           "AIOF_NON_STOP");
-	SQAIOrder.DefSQConst(engine, AIOrder::AIOF_INVALID,            "AIOF_INVALID");
+	SQAIOrder.DefSQConst   (engine, AIOrder::AIOF_NONE,              "AIOF_NONE");
+	SQAIOrder.DefSQConst   (engine, AIOrder::AIOF_TRANSFER,          "AIOF_TRANSFER");
+	SQAIOrder.DefSQConst   (engine, AIOrder::AIOF_UNLOAD,            "AIOF_UNLOAD");
+	SQAIOrder.DefSQConst   (engine, AIOrder::AIOF_FULL_LOAD,         "AIOF_FULL_LOAD");
+	SQAIOrder.DefSQConst   (engine, AIOrder::AIOF_SERVICE_IF_NEEDED, "AIOF_SERVICE_IF_NEEDED");
+	SQAIOrder.DefSQConst   (engine, AIOrder::AIOF_NON_STOP,          "AIOF_NON_STOP");
+	SQAIOrder.DefSQConst   (engine, AIOrder::AIOF_INVALID,           "AIOF_INVALID");
 
-	SQAIOrder.DefSQFunction(engine, &AIOrder::IsValidVehicleOrder, "IsValidVehicleOrder");
-	SQAIOrder.DefSQFunction(engine, &AIOrder::AreOrderFlagsValid,  "AreOrderFlagsValid");
-	SQAIOrder.DefSQFunction(engine, &AIOrder::GetNumberOfOrders,   "GetNumberOfOrders");
-	SQAIOrder.DefSQFunction(engine, &AIOrder::GetOrderDestination, "GetOrderDestination");
-	SQAIOrder.DefSQFunction(engine, &AIOrder::GetOrderFlags,       "GetOrderFlags");
-	SQAIOrder.DefSQFunction(engine, &AIOrder::AppendOrder,         "AppendOrder");
-	SQAIOrder.DefSQFunction(engine, &AIOrder::InsertOrder,         "InsertOrder");
-	SQAIOrder.DefSQFunction(engine, &AIOrder::RemoveOrder,         "RemoveOrder");
-	SQAIOrder.DefSQFunction(engine, &AIOrder::ChangeOrder,         "ChangeOrder");
-	SQAIOrder.DefSQFunction(engine, &AIOrder::CopyOrders,          "CopyOrders");
-	SQAIOrder.DefSQFunction(engine, &AIOrder::ShareOrders,         "ShareOrders");
-	SQAIOrder.DefSQFunction(engine, &AIOrder::UnshareOrders,       "UnshareOrders");
+	SQAIOrder.DefSQFunction(engine, &AIOrder::IsValidVehicleOrder,   "IsValidVehicleOrder");
+	SQAIOrder.DefSQFunction(engine, &AIOrder::AreOrderFlagsValid,    "AreOrderFlagsValid");
+	SQAIOrder.DefSQFunction(engine, &AIOrder::GetNumberOfOrders,     "GetNumberOfOrders");
+	SQAIOrder.DefSQFunction(engine, &AIOrder::GetOrderDestination,   "GetOrderDestination");
+	SQAIOrder.DefSQFunction(engine, &AIOrder::GetOrderFlags,         "GetOrderFlags");
+	SQAIOrder.DefSQFunction(engine, &AIOrder::AppendOrder,           "AppendOrder");
+	SQAIOrder.DefSQFunction(engine, &AIOrder::InsertOrder,           "InsertOrder");
+	SQAIOrder.DefSQFunction(engine, &AIOrder::RemoveOrder,           "RemoveOrder");
+	SQAIOrder.DefSQFunction(engine, &AIOrder::ChangeOrder,           "ChangeOrder");
+	SQAIOrder.DefSQFunction(engine, &AIOrder::CopyOrders,            "CopyOrders");
+	SQAIOrder.DefSQFunction(engine, &AIOrder::ShareOrders,           "ShareOrders");
+	SQAIOrder.DefSQFunction(engine, &AIOrder::UnshareOrders,         "UnshareOrders");
+
 	SQAIOrder.PostRegister(engine);
 }
 #endif /* DEFINE_SQUIRREL_CLASS */
--- a/src/ai/api/ai_road.hpp	Sun Mar 25 13:55:31 2007 +0000
+++ b/src/ai/api/ai_road.hpp	Sun Mar 25 14:19:59 2007 +0000
@@ -113,6 +113,7 @@
 	DefSQClass <AIRoad> SQAIRoad("AIRoad");
 	SQAIRoad.PreRegister(engine);
 	SQAIRoad.AddConstructor(engine);
+
 	SQAIRoad.DefSQFunction(engine, &AIRoad::IsRoadTile,        "IsRoadTile");
 	SQAIRoad.DefSQFunction(engine, &AIRoad::BuildRoad,         "BuildRoad");
 	SQAIRoad.DefSQFunction(engine, &AIRoad::BuildRoadDepot,    "BuildRoadDepot");
@@ -120,6 +121,7 @@
 	SQAIRoad.DefSQFunction(engine, &AIRoad::RemoveRoad,        "RemoveRoad");
 	SQAIRoad.DefSQFunction(engine, &AIRoad::RemoveRoadDepot,   "RemoveRoadDepot");
 	SQAIRoad.DefSQFunction(engine, &AIRoad::RemoveRoadStation, "RemoveRoadStation");
+
 	SQAIRoad.PostRegister(engine);
 }
 #endif /* DEFINE_SQUIRREL_CLASS */
--- a/src/ai/api/ai_settings.hpp	Sun Mar 25 13:55:31 2007 +0000
+++ b/src/ai/api/ai_settings.hpp	Sun Mar 25 14:19:59 2007 +0000
@@ -35,7 +35,9 @@
 	DefSQClass <AISettings> SQAISettings("AISettings");
 	SQAISettings.PreRegister(engine);
 	SQAISettings.AddConstructor(engine);
+
 	SQAISettings.DefSQFunction(engine, &AISettings::SetCommandDelay, "SetCommandDelay");
+
 	SQAISettings.PostRegister(engine);
 }
 #endif /* DEFINE_SQUIRREL_CLASS */
--- a/src/ai/api/ai_sign.hpp	Sun Mar 25 13:55:31 2007 +0000
+++ b/src/ai/api/ai_sign.hpp	Sun Mar 25 14:19:59 2007 +0000
@@ -81,6 +81,7 @@
 	DefSQClass <AISign> SQAISign("AISign");
 	SQAISign.PreRegister(engine);
 	SQAISign.AddConstructor(engine);
+
 	SQAISign.DefSQFunction(engine, &AISign::GetMaxSignID, "GetMaxSignID");
 	SQAISign.DefSQFunction(engine, &AISign::GetSignCount, "GetSignCount");
 	SQAISign.DefSQFunction(engine, &AISign::IsValidSign,  "IsValidSign");
@@ -88,6 +89,7 @@
 	SQAISign.DefSQFunction(engine, &AISign::GetLocation,  "GetLocation");
 	SQAISign.DefSQFunction(engine, &AISign::RemoveSign,   "RemoveSign");
 	SQAISign.DefSQFunction(engine, &AISign::BuildSign,    "BuildSign");
+
 	SQAISign.PostRegister(engine);
 }
 #endif /* DEFINE_SQUIRREL_CLASS */
--- a/src/ai/api/ai_testmode.hpp	Sun Mar 25 13:55:31 2007 +0000
+++ b/src/ai/api/ai_testmode.hpp	Sun Mar 25 14:19:59 2007 +0000
@@ -52,6 +52,8 @@
 	DefSQClass <AITestMode> SQAITestMode("AITestMode");
 	SQAITestMode.PreRegister(engine);
 	SQAITestMode.AddConstructor(engine);
+
+
 	SQAITestMode.PostRegister(engine);
 }
 #endif /* DEFINE_SQUIRREL_CLASS */
--- a/src/ai/api/ai_town.hpp	Sun Mar 25 13:55:31 2007 +0000
+++ b/src/ai/api/ai_town.hpp	Sun Mar 25 14:19:59 2007 +0000
@@ -72,12 +72,14 @@
 	DefSQClass <AITown> SQAITown("AITown");
 	SQAITown.PreRegister(engine);
 	SQAITown.AddConstructor(engine);
+
 	SQAITown.DefSQFunction(engine, &AITown::GetMaxTownID,  "GetMaxTownID");
 	SQAITown.DefSQFunction(engine, &AITown::GetTownCount,  "GetTownCount");
 	SQAITown.DefSQFunction(engine, &AITown::IsValidTown,   "IsValidTown");
 	SQAITown.DefSQFunction(engine, &AITown::GetName,       "GetName");
 	SQAITown.DefSQFunction(engine, &AITown::GetPopulation, "GetPopulation");
 	SQAITown.DefSQFunction(engine, &AITown::GetLocation,   "GetLocation");
+
 	SQAITown.PostRegister(engine);
 }
 #endif /* DEFINE_SQUIRREL_CLASS */
--- a/src/ai/api/ai_transactionmode.hpp	Sun Mar 25 13:55:31 2007 +0000
+++ b/src/ai/api/ai_transactionmode.hpp	Sun Mar 25 14:19:59 2007 +0000
@@ -30,6 +30,21 @@
 		char *text;
 	};
 
+#ifdef DEFINE_SQUIRREL_CLASS
+namespace SQConvert {
+	/* Allow AITransactionMode to be used as Squirrel parameter */
+	template <> AITransactionMode *GetParam(ForceType<AITransactionMode *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AITransactionMode *)instance; }
+}; // namespace SQConvert
+
+void SQAITransactionModeRegister(Squirrel *engine) {
+	DefSQClass <AITransactionMode> SQAITransactionMode("AITransactionMode");
+	SQAITransactionMode.PreRegister(engine);
+	SQAITransactionMode.AddConstructor(engine);
+
+
+	SQAITransactionMode.PostRegister(engine);
+}
+#endif /* DEFINE_SQUIRREL_CLASS */
 	AIModeProc *last_mode;
 	AIObject *last_instance;
 	std::queue<AITransactionModeCommand> command_stack;
@@ -101,23 +116,5 @@
 	void Append(AITransactionMode *transaction);
 };
 
-#ifdef DEFINE_SQUIRREL_CLASS
-namespace SQConvert {
-	/* Allow AITransactionMode to be used as Squirrel parameter */
-	template <> AITransactionMode *GetParam(ForceType<AITransactionMode *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AITransactionMode *)instance; }
-}; // namespace SQConvert
-
-void SQAITransactionModeRegister(Squirrel *engine) {
-	DefSQClass <AITransactionMode> SQAITransactionMode("AITransactionMode");
-	SQAITransactionMode.PreRegister(engine);
-	SQAITransactionMode.AddConstructor(engine);
-	SQAITransactionMode.DefSQFunction(engine, &AITransactionMode::Execute,  "Execute");
-	SQAITransactionMode.DefSQFunction(engine, &AITransactionMode::Stop,     "Stop");
-	SQAITransactionMode.DefSQFunction(engine, &AITransactionMode::Rollback, "Rollback");
-	SQAITransactionMode.DefSQFunction(engine, &AITransactionMode::GetCosts, "GetCosts");
-	SQAITransactionMode.DefSQFunction(engine, &AITransactionMode::Append,   "Append");
-	SQAITransactionMode.PostRegister(engine);
-}
-#endif /* DEFINE_SQUIRREL_CLASS */
 
 #endif /* AI_TRANSACTIONMODE_HPP */
--- a/src/ai/api/ai_vehicle.hpp	Sun Mar 25 13:55:31 2007 +0000
+++ b/src/ai/api/ai_vehicle.hpp	Sun Mar 25 14:19:59 2007 +0000
@@ -124,6 +124,7 @@
 	DefSQClass <AIVehicle> SQAIVehicle("AIVehicle");
 	SQAIVehicle.PreRegister(engine);
 	SQAIVehicle.AddConstructor(engine);
+
 	SQAIVehicle.DefSQFunction(engine, &AIVehicle::IsValidEngine,       "IsValidEngine");
 	SQAIVehicle.DefSQFunction(engine, &AIVehicle::IsValidVehicle,      "IsValidVehicle");
 	SQAIVehicle.DefSQFunction(engine, &AIVehicle::FindBestRoadVehicle, "FindBestRoadVehicle");
@@ -134,6 +135,7 @@
 	SQAIVehicle.DefSQFunction(engine, &AIVehicle::SendVehicleToDepot,  "SendVehicleToDepot");
 	SQAIVehicle.DefSQFunction(engine, &AIVehicle::StartStopVehicle,    "StartStopVehicle");
 	SQAIVehicle.DefSQFunction(engine, &AIVehicle::SkipVehicleOrder,    "SkipVehicleOrder");
+
 	SQAIVehicle.PostRegister(engine);
 }
 #endif /* DEFINE_SQUIRREL_CLASS */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ai/api/squirrel_export.awk	Sun Mar 25 14:19:59 2007 +0000
@@ -0,0 +1,178 @@
+#
+# Awk script to automatically generate the code needed
+# to export the AI API to Squirrel.
+#
+# Note that arrays are 1 based...
+#
+
+# Simple insertion sort.
+function array_sort(ARRAY, ELEMENTS, temp, i, j) {
+	for (i = 2; i <= ELEMENTS; i++)
+		for (j = i; ARRAY[j - 1] > ARRAY[j]; --j) {
+			temp = ARRAY[j]
+			ARRAY[j] = ARRAY[j - 1]
+			ARRAY[j - 1] = temp
+	}
+	return
+}
+
+BEGIN {
+	enum_size = 0
+	struct_size = 0
+	method_size = 0
+	enum_value_size = 0
+	cls = ""
+	start_squirrel_define_on_next_line = "false"
+	cls_level = 0
+}
+
+# Remove the old squirrel stuff
+/#ifdef DEFINE_SQUIRREL_CLASS/ { squirrel_stuff = "true";  next; }
+/^#endif \/\* DEFINE_SQUIRREL_CLASS \*\// { if (squirrel_stuff == "true") { squirrel_stuff = "false"; next; } }
+{ if (squirrel_stuff == "true") next; }
+
+{ print $0; }
+
+# We only want to have public functions exported for now
+/^(	*)class/     { if (cls_level == 0) { public = "false"; cls = $2;} cls_level++; next; }
+/^(	*)public/    { if (cls_level == 1) public = "true";  next; }
+/^(	*)protected/ { if (cls_level == 1) public = "false"; next; }
+/^(	*)private/   { if (cls_level == 1) public = "false"; next; }
+
+# Ignore the comments
+/^#/             { next; }
+/\/\*.*\*\//     { comment = "false"; next; }
+/\/\*/           { comment = "true";  next; }
+/\*\//           { comment = "false"; next; }
+{ if (comment == "true") next }
+
+# We need to make specialized conversions for structs
+#/^(	*)struct/ {
+#	cls_level++
+#	if (public == "false") next;
+#	struct_size++
+#	structs[struct_size] = cls "::" $2
+#	next
+#}
+
+# We need to make specialized conversions for enums
+/^(	*)enum/ {
+	cls_level++
+	if (public == "false") next;
+	in_enum = "true"
+	enum_size++
+	enums[enum_size] = cls "::" $2
+	next
+}
+
+# Maybe the end of the class, if so we can start with the Squirrel export pretty soon
+/};/ {
+	cls_level--
+	if (cls_level != 0) {
+		in_enum = "false";
+		next;
+	}
+	if (cls == "") {
+		next;
+	}
+	start_squirrel_define_on_next_line = "true"
+	next;
+}
+
+# Empty/white lines. When we may do the Squirrel export, do that export.
+/^([ 	]*)$/ {
+	if (start_squirrel_define_on_next_line == "false") next
+	spaces = "                                                               ";
+	public = "false"
+	print "#ifdef DEFINE_SQUIRREL_CLASS"
+	namespace_opened = "false"
+
+	# First check whether we have enums to print
+	if (enum_size != 0) {
+		if (namespace_opened == "false") {
+			print "namespace SQConvert {"
+			namespace_opened = "true"
+		}
+		print "	/* Allow enums to be used as Squirrel parameters */"
+		for (i = 1; i <= enum_size; i++) {
+			print "	template <> " enums[i] " GetParam(ForceType<" enums[i] ">, HSQUIRRELVM vm, int index) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (" enums[i] ")tmp; }"
+			print "	template <> int Return<" enums[i] ">(HSQUIRRELVM vm, " enums[i] " res) { sq_pushinteger(vm, (int32)res); return 1; }"
+			delete enums[i]
+		}
+	}
+
+	if (namespace_opened == "false") {
+		print "namespace SQConvert {"
+		namespace_opened = "true"
+	} else {
+		print ""
+	}
+	print "	/* Allow " cls " to be used as Squirrel parameter */"
+	print "	template <> " cls " *GetParam(ForceType<" cls " *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (" cls " *)instance; }"
+	# TODO returning...
+
+	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 "\");"
+	print "	SQ" cls ".PreRegister(engine);"
+	print "	SQ" cls ".AddConstructor(engine);"
+	print ""
+	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 <= method_size; i++) {
+		if (mlen <= length(methods[i])) mlen = length(methods[i]) + 1 #one character (&) longer
+	}
+
+	for (i = 1; i <= enum_value_size; i++) {
+		print "	SQ" cls ".DefSQConst   (engine, " cls "::" enum_value[i] ", " substr(spaces, 0, mlen - length(enum_value[i]) + 1) "\""  enum_value[i] "\");"
+		delete enum_value[i]
+	}
+	if (enum_value_size != 0) print ""
+
+
+	for (i = 1; i <= method_size; i++) {
+		print "	SQ" cls ".DefSQFunction(engine, &" cls "::" methods[i] ", " substr(spaces, 0, mlen - length(methods[i])) "\""  methods[i] "\");"
+		delete methods[i]
+	}
+	print ""
+	print "	SQ" cls ".PostRegister(engine);"
+	print "}"
+
+	print "#endif /* DEFINE_SQUIRREL_CLASS */"
+
+	cls = ""
+	start_squirrel_define_on_next_line = "false"
+	enum_size = 0
+	struct_size = 0
+	method_size = 0
+}
+
+# Skip non-public functions
+{ if (public == "false") next }
+
+# Add enums
+{
+	if (in_enum == "true") {
+		enum_value_size++
+		enum_value[enum_value_size] = $1
+		next
+	}
+}
+
+# Add a method to the list
+/^.*$/ {
+	if (cls_level != 1) next
+	gsub("virtual", "", $0)
+	gsub("static", "", $0)
+	gsub("\*", "", $0)
+	gsub("\(.*", "", $0)
+	if ($2 == "") next
+	method_size++
+	methods[method_size] = $2
+	next
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ai/api/squirrel_export.sh	Sun Mar 25 14:19:59 2007 +0000
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+# This must be called from within the src/ai/api directory.
+
+for f in `ls *.hpp `; do
+	case "$f" in
+		# these files should not be changed by this script
+		"ai_controller.hpp" | "ai_object.hpp") continue;
+	esac
+	awk -f squirrel_export.awk ${f} > ${f}.tmp
+	if [ -n "`diff ${f} ${f}.tmp`" ]; then
+		mv ${f}.tmp ${f}
+	else
+		rm -f ${f}.tmp
+	fi
+done