(svn r9360) [NoAI] -Add: class-functions can now be static and still be added to SQ. There they behave as they are non-static, which is fine for that level of coding. noai
authortruelight
Tue, 20 Mar 2007 00:14:29 +0000
branchnoai
changeset 9490 999eb7531205
parent 9489 d7ee0a65ead9
child 9491 351239ad524c
(svn r9360) [NoAI] -Add: class-functions can now be static and still be added to SQ. There they behave as they are non-static, which is fine for that level of coding.
-Change: changed IsValidCargo to a static member
src/ai/api/ai_cargo.hpp
src/squirrel_helper.hpp
--- a/src/ai/api/ai_cargo.hpp	Tue Mar 20 00:12:35 2007 +0000
+++ b/src/ai/api/ai_cargo.hpp	Tue Mar 20 00:14:29 2007 +0000
@@ -17,7 +17,7 @@
 	 * @param cargo_type the cargo to check.
 	 * @return true if and only if the cargo type is valid.
 	 */
-	bool IsValidCargo(CargoID cargo_type);
+	static bool IsValidCargo(CargoID cargo_type);
 
 	/**
 	 * Gets the string representation of the cargo label.
--- a/src/squirrel_helper.hpp	Tue Mar 20 00:12:35 2007 +0000
+++ b/src/squirrel_helper.hpp	Tue Mar 20 00:14:29 2007 +0000
@@ -28,7 +28,7 @@
 	template <typename T> static T GetParam(ForceType<T>, HSQUIRRELVM vm, int index);
 
 	/**
-	 * The real C++ caller for function with a return value and 0 params.
+	 * The real C++ caller for method with a return value and 0 params.
 	 */
 	template <typename CL, typename RT>
 	static int SQCall(CL *instance, RT (CL::*func)(), HSQUIRRELVM vm)
@@ -37,7 +37,16 @@
 	}
 
 	/**
-	 * The real C++ caller for function with no return value and 0 params.
+	 * The real C++ caller for function with a return value and 0 params.
+	 */
+	template <typename CL, typename RT>
+	static int SQCall(CL *instance, RT (*func)(), HSQUIRRELVM vm)
+	{
+		return Return(vm, (*func)());
+	}
+
+	/**
+	 * The real C++ caller for method with no return value and 0 params.
 	 */
 	template <typename CL>
 	static int SQCall(CL *instance, void (CL::*func)(), HSQUIRRELVM vm)
@@ -47,7 +56,17 @@
 	}
 
 	/**
-	 * The real C++ caller for function with a return value and 1 param.
+	 * The real C++ caller for function with no return value and 0 params.
+	 */
+	template <typename CL>
+	static int SQCall(CL *instance, void (*func)(), HSQUIRRELVM vm)
+	{
+		(*func)();
+		return 0;
+	}
+
+	/**
+	 * The real C++ caller for method with a return value and 1 param.
 	 */
 	template <typename CL, typename RT, typename P1>
 	static int SQCall(CL *instance, RT (CL::*func)(P1), HSQUIRRELVM vm)
@@ -58,7 +77,18 @@
 	}
 
 	/**
-	 * The real C++ caller for function with no return value and 1 param.
+	 * The real C++ caller for function with a return value and 1 param.
+	 */
+	template <typename CL, typename RT, typename P1>
+	static int SQCall(CL *instance, RT (*func)(P1), HSQUIRRELVM vm)
+	{
+		return Return(vm, (*func)(
+						GetParam(ForceType<P1>(), vm, 2)
+					));
+	}
+
+	/**
+	 * The real C++ caller for method with no return value and 1 param.
 	 */
 	template <typename CL, typename P1>
 	static int SQCall(CL *instance, void (CL::*func)(P1), HSQUIRRELVM vm)
@@ -70,7 +100,19 @@
 	}
 
 	/**
-	 * The real C++ caller for function with a return value and 2 params.
+	 * The real C++ caller for function with no return value and 1 param.
+	 */
+	template <typename CL, typename P1>
+	static int SQCall(CL *instance, void (*func)(P1), HSQUIRRELVM vm)
+	{
+		(*func)(
+						GetParam(ForceType<P1>(), vm, 2)
+					);
+		return 0;
+	}
+
+	/**
+	 * The real C++ caller for method with a return value and 2 params.
 	 */
 	template <typename CL, typename RT, typename P1, typename P2>
 	static int SQCall(CL *instance, RT (CL::*func)(P1, P2), HSQUIRRELVM vm)
@@ -82,7 +124,19 @@
 	}
 
 	/**
-	 * The real C++ caller for function with no return value and 2 params.
+	 * The real C++ caller for function with a return value and 2 params.
+	 */
+	template <typename CL, typename RT, typename P1, typename P2>
+	static int SQCall(CL *instance, RT (*func)(P1, P2), HSQUIRRELVM vm)
+	{
+		return Return(vm, (*func)(
+						GetParam(ForceType<P1>(), vm, 2),
+						GetParam(ForceType<P2>(), vm, 3)
+					));
+	}
+
+	/**
+	 * The real C++ caller for method with no return value and 2 params.
 	 */
 	template <typename CL, typename P1, typename P2>
 	static int SQCall(CL *instance, void (CL::*func)(P1, P2), HSQUIRRELVM vm)
@@ -95,7 +149,20 @@
 	}
 
 	/**
-	 * The real C++ caller for function with a return value and 3 params.
+	 * The real C++ caller for function with no return value and 2 params.
+	 */
+	template <typename CL, typename P1, typename P2>
+	static int SQCall(CL *instance, void (*func)(P1, P2), HSQUIRRELVM vm)
+	{
+		(*func)(
+						GetParam(ForceType<P1>(), vm, 2),
+						GetParam(ForceType<P2>(), vm, 3)
+					);
+		return 0;
+	}
+
+	/**
+	 * The real C++ caller for method with a return value and 3 params.
 	 */
 	template <typename CL, typename RT, typename P1, typename P2, typename P3>
 	static int SQCall(CL *instance, RT (CL::*func)(P1, P2, P3), HSQUIRRELVM vm)
@@ -108,7 +175,20 @@
 	}
 
 	/**
-	 * The real C++ caller for function with no return value and 3 params.
+	 * The real C++ caller for function with a return value and 3 params.
+	 */
+	template <typename CL, typename RT, typename P1, typename P2, typename P3>
+	static int SQCall(CL *instance, RT (*func)(P1, P2, P3), HSQUIRRELVM vm)
+	{
+		return Return(vm, (*func)(
+						GetParam(ForceType<P1>(), vm, 2),
+						GetParam(ForceType<P2>(), vm, 3),
+						GetParam(ForceType<P3>(), vm, 4)
+					));
+	}
+
+	/**
+	 * The real C++ caller for method with no return value and 3 params.
 	 */
 	template <typename CL, typename P1, typename P2, typename P3>
 	static int SQCall(CL *instance, void (CL::*func)(P1, P2, P3), HSQUIRRELVM vm)
@@ -122,7 +202,21 @@
 	}
 
 	/**
-	 * The real C++ caller for function with a return value and 4 params.
+	 * The real C++ caller for function with no return value and 3 params.
+	 */
+	template <typename CL, typename P1, typename P2, typename P3>
+	static int SQCall(CL *instance, void (*func)(P1, P2, P3), HSQUIRRELVM vm)
+	{
+		(*func)(
+						GetParam(ForceType<P1>(), vm, 2),
+						GetParam(ForceType<P2>(), vm, 3),
+						GetParam(ForceType<P3>(), vm, 4)
+					);
+		return 0;
+	}
+
+	/**
+	 * The real C++ caller for method with a return value and 4 params.
 	 */
 	template <typename CL, typename RT, typename P1, typename P2, typename P3, typename P4>
 	static int SQCall(CL *instance, RT (CL::*func)(P1, P2, P3, P4), HSQUIRRELVM vm)
@@ -136,7 +230,21 @@
 	}
 
 	/**
-	 * The real C++ caller for function with no return value and 4 params.
+	 * The real C++ caller for function with a return value and 4 params.
+	 */
+	template <typename CL, typename RT, typename P1, typename P2, typename P3, typename P4>
+	static int SQCall(CL *instance, RT (*func)(P1, P2, P3, P4), HSQUIRRELVM vm)
+	{
+		return Return(vm, (*func)(
+						GetParam(ForceType<P1>(), vm, 2),
+						GetParam(ForceType<P2>(), vm, 3),
+						GetParam(ForceType<P3>(), vm, 4),
+						GetParam(ForceType<P3>(), vm, 5)
+					));
+	}
+
+	/**
+	 * The real C++ caller for method with no return value and 4 params.
 	 */
 	template <typename CL, typename P1, typename P2, typename P3, typename P4>
 	static int SQCall(CL *instance, void (CL::*func)(P1, P2, P3, P4), HSQUIRRELVM vm)
@@ -151,6 +259,21 @@
 	}
 
 	/**
+	 * The real C++ caller for function with no return value and 4 params.
+	 */
+	template <typename CL, typename P1, typename P2, typename P3, typename P4>
+	static int SQCall(CL *instance, void (*func)(P1, P2, P3, P4), HSQUIRRELVM vm)
+	{
+		(*func)(
+						GetParam(ForceType<P1>(), vm, 2),
+						GetParam(ForceType<P2>(), vm, 3),
+						GetParam(ForceType<P3>(), vm, 4),
+						GetParam(ForceType<P3>(), vm, 5)
+					);
+		return 0;
+	}
+
+	/**
 	 * A general template for all callback functions from Squirrel.
 	 *  In here the function_proc is recovered, and the SQCall is called that
 	 *  can handle this exact amount of params.