# HG changeset patch
# User truelight
# Date 1174554600 0
# Node ID 261d33fbabb8ba2c46cf4e8ebfa75b9b252d1c38
# Parent 86ff6927e68a472b5a3bb5c1f7a9f9a8edae1280
(svn r9406) [NoAI] -Fix: made the detection of 'void' against 'non-void' functions for the class->SQ convertor via templates (as MSVC failed to understand the other method) (KUDr)
-Fix: merged squirrel_helper.cpp to squirrel_helper.hpp, as that was a silly attempt of TrueLight (KUDr)
-Fix: put all Squirrel conversion code in a namespace instead of a class (to avoid G++ bitching) (KUDr)
diff -r 86ff6927e68a -r 261d33fbabb8 projects/openttd.vcproj
--- a/projects/openttd.vcproj Thu Mar 22 08:58:17 2007 +0000
+++ b/projects/openttd.vcproj Thu Mar 22 09:10:00 2007 +0000
@@ -347,9 +347,6 @@
RelativePath=".\..\src\squirrel.cpp">
-
-
-
-
diff -r 86ff6927e68a -r 261d33fbabb8 source.list
--- a/source.list Thu Mar 22 08:58:17 2007 +0000
+++ b/source.list Thu Mar 22 09:10:00 2007 +0000
@@ -68,7 +68,6 @@
string.cpp
strings.cpp
squirrel.cpp
-squirrel_helper.cpp
squirrel_std.cpp
texteff.cpp
tgp.cpp
diff -r 86ff6927e68a -r 261d33fbabb8 src/ai/api/ai_order.hpp
--- a/src/ai/api/ai_order.hpp Thu Mar 22 08:58:17 2007 +0000
+++ b/src/ai/api/ai_order.hpp Thu Mar 22 09:10:00 2007 +0000
@@ -156,9 +156,12 @@
DECLARE_ENUM_AS_BIT_SET(AIOrder::AIOrderFlags);
#ifdef DEFINE_SQUIRREL_CLASS
+
/* Custom template to allow AIOrderFlags as param */
-template <> AIOrder::AIOrderFlags SQConvert::GetParam(ForceType, HSQUIRRELVM vm, int index) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AIOrder::AIOrderFlags)tmp; }
-template <> int SQConvert::Return(HSQUIRRELVM vm, AIOrder::AIOrderFlags res) { sq_pushinteger(vm, (int32)res); return 1; }
+namespace SQConvert {
+ template <> AIOrder::AIOrderFlags GetParam(ForceType, HSQUIRRELVM vm, int index) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AIOrder::AIOrderFlags)tmp; }
+ template <> int Return(HSQUIRRELVM vm, AIOrder::AIOrderFlags res) { sq_pushinteger(vm, (int32)res); return 1; }
+}; // namespace SQConvert
void SQAIOrderRegister(Squirrel *engine) {
DefSQClass SQAIOrder("AIOrder");
diff -r 86ff6927e68a -r 261d33fbabb8 src/ai/api/ai_transactionmode.hpp
--- a/src/ai/api/ai_transactionmode.hpp Thu Mar 22 08:58:17 2007 +0000
+++ b/src/ai/api/ai_transactionmode.hpp Thu Mar 22 09:10:00 2007 +0000
@@ -103,7 +103,9 @@
#ifdef DEFINE_SQUIRREL_CLASS
/* Custom template to allow AITransactionMode-instance as param */
-template <> AITransactionMode *SQConvert::GetParam(ForceType, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AITransactionMode *)instance; }
+namespace SQConvert {
+ template <> AITransactionMode *GetParam(ForceType, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AITransactionMode *)instance; }
+}; // namespace SQConvert
void SQAITransactionModeRegister(Squirrel *engine) {
DefSQClass SQAITransactionMode("AITransactionMode");
diff -r 86ff6927e68a -r 261d33fbabb8 src/squirrel_helper.cpp
--- a/src/squirrel_helper.cpp Thu Mar 22 08:58:17 2007 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-/* $Id$ */
-
-/** @file squirrel_helper.cpp parts of the implementation of the class for convert code */
-
-#include "stdafx.h"
-#include "squirrel_helper.hpp"
-
-template <> int SQConvert::Return (HSQUIRRELVM vm, uint8 res) { sq_pushinteger(vm, (int32)res); return 1; }
-template <> int SQConvert::Return(HSQUIRRELVM vm, uint16 res) { sq_pushinteger(vm, (int32)res); return 1; }
-template <> int SQConvert::Return(HSQUIRRELVM vm, uint32 res) { sq_pushinteger(vm, (int32)res); return 1; }
-template <> int SQConvert::Return (HSQUIRRELVM vm, int8 res) { sq_pushinteger(vm, res); return 1; }
-template <> int SQConvert::Return (HSQUIRRELVM vm, int16 res) { sq_pushinteger(vm, res); return 1; }
-template <> int SQConvert::Return (HSQUIRRELVM vm, int32 res) { sq_pushinteger(vm, res); return 1; }
-template <> int SQConvert::Return (HSQUIRRELVM vm, bool res) { sq_pushbool (vm, res); return 1; }
-template <> int SQConvert::Return(HSQUIRRELVM vm, char *res) { if (res == NULL) sq_pushnull(vm); else sq_pushstring (vm, OTTD2FS(res), strlen(res)); free(res); return 1; }
-
-template <> uint8 SQConvert::GetParam(ForceType , HSQUIRRELVM vm, int index) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return tmp; }
-template <> uint16 SQConvert::GetParam(ForceType , HSQUIRRELVM vm, int index) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return tmp; }
-template <> uint32 SQConvert::GetParam(ForceType , HSQUIRRELVM vm, int index) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return tmp; }
-template <> int8 SQConvert::GetParam(ForceType , HSQUIRRELVM vm, int index) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return tmp; }
-template <> int16 SQConvert::GetParam(ForceType , HSQUIRRELVM vm, int index) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return tmp; }
-template <> int32 SQConvert::GetParam(ForceType , HSQUIRRELVM vm, int index) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return tmp; }
-template <> bool SQConvert::GetParam(ForceType , HSQUIRRELVM vm, int index) { SQBool tmp; sq_getbool (vm, index, &tmp); return tmp != 0; }
-template <> const char *SQConvert::GetParam(ForceType, HSQUIRRELVM vm, int index) { const SQChar *tmp; sq_getstring (vm, index, &tmp); return FS2OTTD(tmp); }
diff -r 86ff6927e68a -r 261d33fbabb8 src/squirrel_helper.hpp
--- a/src/squirrel_helper.hpp Thu Mar 22 08:58:17 2007 +0000
+++ b/src/squirrel_helper.hpp Thu Mar 22 09:10:00 2007 +0000
@@ -8,10 +8,39 @@
#include
/**
- * The Squirrel convert class. It doesn't have an instance, the methods only are used.
+ * The Squirrel convert routines
*/
-class SQConvert {
-public:
+namespace SQConvert {
+
+ template struct YesT {
+ static const bool Yes = Y;
+ static const bool No = !Y;
+ };
+
+ /**
+ * Helper class to recognize if the given type is void. Usage: 'IsVoidT::Yes'
+ */
+ template struct IsVoidT : YesT {};
+ template <> struct IsVoidT : YesT {};
+
+ /**
+ * Helper class to recognize if the function/method return type is void.
+ */
+ template struct HasVoidReturnT;
+ /* functions */
+ template struct HasVoidReturnT : IsVoidT {};
+ template struct HasVoidReturnT : IsVoidT {};
+ template struct HasVoidReturnT : IsVoidT {};
+ template struct HasVoidReturnT : IsVoidT {};
+ template struct HasVoidReturnT : IsVoidT {};
+ /* methods */
+ template struct HasVoidReturnT : IsVoidT {};
+ template struct HasVoidReturnT : IsVoidT {};
+ template struct HasVoidReturnT : IsVoidT {};
+ template struct HasVoidReturnT : IsVoidT {};
+ template struct HasVoidReturnT : IsVoidT {};
+
+
/**
* Special class to make it possible for the compiler to pick the correct GetParam().
*/
@@ -22,264 +51,330 @@
*/
template static int Return(HSQUIRRELVM vm, T t);
+ template <> inline int Return (HSQUIRRELVM vm, uint8 res) { sq_pushinteger(vm, (int32)res); return 1; }
+ template <> inline int Return(HSQUIRRELVM vm, uint16 res) { sq_pushinteger(vm, (int32)res); return 1; }
+ template <> inline int Return(HSQUIRRELVM vm, uint32 res) { sq_pushinteger(vm, (int32)res); return 1; }
+ template <> inline int Return (HSQUIRRELVM vm, int8 res) { sq_pushinteger(vm, res); return 1; }
+ template <> inline int Return (HSQUIRRELVM vm, int16 res) { sq_pushinteger(vm, res); return 1; }
+ template <> inline int Return (HSQUIRRELVM vm, int32 res) { sq_pushinteger(vm, res); return 1; }
+ template <> inline int Return (HSQUIRRELVM vm, bool res) { sq_pushbool (vm, res); return 1; }
+ template <> inline int Return(HSQUIRRELVM vm, char *res) { if (res == NULL) sq_pushnull(vm); else sq_pushstring (vm, OTTD2FS(res), strlen(res)); free(res); return 1; }
+
/**
* To get a param from squirrel, we call this function. It converts to the right format.
*/
template static T GetParam(ForceType, HSQUIRRELVM vm, int index);
- /**
- * The real C++ caller for method with a return value and 0 params.
- */
- template
- static int SQCall(CL *instance, RT (CL::*func)(), HSQUIRRELVM vm)
- {
- return Return(vm, (instance->*func)());
- }
+ template <> inline uint8 GetParam(ForceType , HSQUIRRELVM vm, int index) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return tmp; }
+ template <> inline uint16 GetParam(ForceType , HSQUIRRELVM vm, int index) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return tmp; }
+ template <> inline uint32 GetParam(ForceType , HSQUIRRELVM vm, int index) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return tmp; }
+ template <> inline int8 GetParam(ForceType , HSQUIRRELVM vm, int index) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return tmp; }
+ template <> inline int16 GetParam(ForceType , HSQUIRRELVM vm, int index) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return tmp; }
+ template <> inline int32 GetParam(ForceType , HSQUIRRELVM vm, int index) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return tmp; }
+ template <> inline bool GetParam(ForceType , HSQUIRRELVM vm, int index) { SQBool tmp; sq_getbool (vm, index, &tmp); return tmp != 0; }
+ template <> inline const char *GetParam(ForceType, HSQUIRRELVM vm, int index) { const SQChar *tmp; sq_getstring (vm, index, &tmp); return FS2OTTD(tmp); }
/**
- * The real C++ caller for function with a return value and 0 params.
- */
- template
- static int SQCall(CL *instance, RT (*func)(), HSQUIRRELVM vm)
- {
- return Return(vm, (*func)());
- }
+ * Helper class to recognize the function type (retval type, args) and use the proper specialization
+ * for SQ callback. The partial specializations for the second arg (Tis_void_retval) are not possible
+ * on the function. Therefore the class is used instead.
+ */
+ template ::Yes> struct HelperT;
/**
- * The real C++ caller for method with no return value and 0 params.
+ * The real C++ caller for function with return value and 0 params.
*/
- template
- static int SQCall(CL *instance, void (CL::*func)(), HSQUIRRELVM vm)
- {
- (instance->*func)();
- return 0;
- }
+ template
+ struct HelperT {
+ static int SQCall(void *instance, Tretval (*func)(), HSQUIRRELVM vm)
+ {
+ return Return(vm, (*func)());
+ }
+ };
/**
* The real C++ caller for function with no return value and 0 params.
*/
- template
- static int SQCall(CL *instance, void (*func)(), HSQUIRRELVM vm)
- {
- (*func)();
- return 0;
- }
+ template
+ struct HelperT {
+ static int SQCall(void *instance, Tretval (*func)(), HSQUIRRELVM vm)
+ {
+ (*func)();
+ return 0;
+ }
+ };
/**
- * The real C++ caller for method with a return value and 1 param.
+ * The real C++ caller for method with return value and 0 params.
*/
- template
- static int SQCall(CL *instance, RT (CL::*func)(P1), HSQUIRRELVM vm)
- {
- return Return(vm, (instance->*func)(
- GetParam(ForceType(), vm, 2)
- ));
- }
+ template
+ struct HelperT {
+ static int SQCall(Tcls *instance, Tretval (Tcls::*func)(), HSQUIRRELVM vm)
+ {
+ return Return(vm, (instance->*func)());
+ }
+ };
/**
- * The real C++ caller for function with a return value and 1 param.
+ * The real C++ caller for method with no return value and 0 params.
*/
- template
- static int SQCall(CL *instance, RT (*func)(P1), HSQUIRRELVM vm)
- {
- return Return(vm, (*func)(
- GetParam(ForceType(), vm, 2)
- ));
- }
+ template
+ struct HelperT {
+ static int SQCall(Tcls *instance, Tretval (Tcls::*func)(), HSQUIRRELVM vm)
+ {
+ (instance->*func)();
+ return 0;
+ }
+ };
+
+ /**
+ * The real C++ caller for function with return value and 1 param.
+ */
+ template
+ struct HelperT {
+ static int SQCall(void *instance, Tretval (*func)(Targ1), HSQUIRRELVM vm)
+ {
+ return Return(vm, (*func)(
+ GetParam(ForceType(), vm, 2)
+ ));
+ }
+ };
+
+ /**
+ * The real C++ caller for function with no return value and 1 param.
+ */
+ template
+ struct HelperT {
+ static int SQCall(void *instance, Tretval (*func)(Targ1), HSQUIRRELVM vm)
+ {
+ (*func)(
+ GetParam(ForceType(), vm, 2)
+ );
+ return 0;
+ }
+ };
+
+ /**
+ * The real C++ caller for method with return value and 1 param.
+ */
+ template
+ struct HelperT {
+ static int SQCall(Tcls *instance, Tretval (Tcls::*func)(Targ1), HSQUIRRELVM vm)
+ {
+ return Return(vm, (instance->*func)(
+ GetParam(ForceType(), vm, 2)
+ ));
+ }
+ };
/**
* The real C++ caller for method with no return value and 1 param.
*/
- template
- static int SQCall(CL *instance, void (CL::*func)(P1), HSQUIRRELVM vm)
- {
- (instance->*func)(
- GetParam(ForceType(), vm, 2)
- );
- return 0;
- }
-
- /**
- * The real C++ caller for function with no return value and 1 param.
- */
- template
- static int SQCall(CL *instance, void (*func)(P1), HSQUIRRELVM vm)
- {
- (*func)(
- GetParam(ForceType(), vm, 2)
- );
- return 0;
- }
+ template
+ struct HelperT {
+ static int SQCall(Tcls *instance, Tretval (Tcls::*func)(Targ1), HSQUIRRELVM vm)
+ {
+ (instance->*func)(
+ GetParam(ForceType(), vm, 2)
+ );
+ return 0;
+ }
+ };
/**
- * The real C++ caller for method with a return value and 2 params.
+ * The real C++ caller for function with return value and 2 params.
*/
- template
- static int SQCall(CL *instance, RT (CL::*func)(P1, P2), HSQUIRRELVM vm)
- {
- return Return(vm, (instance->*func)(
- GetParam(ForceType(), vm, 2),
- GetParam(ForceType(), vm, 3)
- ));
- }
+ template
+ struct HelperT {
+ static int SQCall(void *instance, Tretval (*func)(Targ1, Targ2), HSQUIRRELVM vm)
+ {
+ return Return(vm, (*func)(
+ GetParam(ForceType(), vm, 2),
+ GetParam(ForceType(), vm, 3)
+ ));
+ }
+ };
/**
- * The real C++ caller for function with a return value and 2 params.
+ * The real C++ caller for function with no return value and 2 params.
*/
- template
- static int SQCall(CL *instance, RT (*func)(P1, P2), HSQUIRRELVM vm)
- {
- return Return(vm, (*func)(
- GetParam(ForceType(), vm, 2),
- GetParam(ForceType(), vm, 3)
- ));
- }
+ template
+ struct HelperT {
+ static int SQCall(void *instance, Tretval (*func)(Targ1, Targ2), HSQUIRRELVM vm)
+ {
+ (*func)(
+ GetParam(ForceType(), vm, 2),
+ GetParam(ForceType(), vm, 3)
+ );
+ return 0;
+ }
+ };
+
+ /**
+ * The real C++ caller for method with return value and 2 params.
+ */
+ template
+ struct HelperT {
+ static int SQCall(Tcls *instance, Tretval (Tcls::*func)(Targ1, Targ2), HSQUIRRELVM vm)
+ {
+ return Return(vm, (instance->*func)(
+ GetParam(ForceType(), vm, 2),
+ GetParam(ForceType(), vm, 3)
+ ));
+ }
+ };
/**
* The real C++ caller for method with no return value and 2 params.
*/
- template
- static int SQCall(CL *instance, void (CL::*func)(P1, P2), HSQUIRRELVM vm)
- {
- (instance->*func)(
- GetParam(ForceType(), vm, 2),
- GetParam(ForceType(), vm, 3)
- );
- return 0;
- }
-
- /**
- * The real C++ caller for function with no return value and 2 params.
- */
- template
- static int SQCall(CL *instance, void (*func)(P1, P2), HSQUIRRELVM vm)
- {
- (*func)(
- GetParam(ForceType(), vm, 2),
- GetParam(ForceType(), vm, 3)
- );
- return 0;
- }
+ template
+ struct HelperT {
+ static int SQCall(Tcls *instance, Tretval (Tcls::*func)(Targ1, Targ2), HSQUIRRELVM vm)
+ {
+ (instance->*func)(
+ GetParam(ForceType(), vm, 2),
+ GetParam(ForceType(), vm, 3)
+ );
+ return 0;
+ }
+ };
/**
- * The real C++ caller for method with a return value and 3 params.
- */
- template
- static int SQCall(CL *instance, RT (CL::*func)(P1, P2, P3), HSQUIRRELVM vm)
- {
- return Return(vm, (instance->*func)(
- GetParam(ForceType(), vm, 2),
- GetParam(ForceType(), vm, 3),
- GetParam(ForceType(), vm, 4)
- ));
- }
-
- /**
- * The real C++ caller for function with a return value and 3 params.
+ * The real C++ caller for function with return value and 3 params.
*/
- template
- static int SQCall(CL *instance, RT (*func)(P1, P2, P3), HSQUIRRELVM vm)
- {
- return Return(vm, (*func)(
- GetParam(ForceType(), vm, 2),
- GetParam(ForceType(), vm, 3),
- GetParam(ForceType(), vm, 4)
- ));
- }
-
- /**
- * The real C++ caller for method with no return value and 3 params.
- */
- template
- static int SQCall(CL *instance, void (CL::*func)(P1, P2, P3), HSQUIRRELVM vm)
- {
- (instance->*func)(
- GetParam(ForceType(), vm, 2),
- GetParam(ForceType(), vm, 3),
- GetParam(ForceType(), vm, 4)
- );
- return 0;
- }
+ template
+ struct HelperT {
+ static int SQCall(void *instance, Tretval (*func)(Targ1, Targ2, Targ3), HSQUIRRELVM vm)
+ {
+ return Return(vm, (*func)(
+ GetParam(ForceType(), vm, 2),
+ GetParam(ForceType(), vm, 3),
+ GetParam(ForceType(), vm, 4)
+ ));
+ }
+ };
/**
* The real C++ caller for function with no return value and 3 params.
*/
- template
- static int SQCall(CL *instance, void (*func)(P1, P2, P3), HSQUIRRELVM vm)
- {
- (*func)(
- GetParam(ForceType(), vm, 2),
- GetParam(ForceType(), vm, 3),
- GetParam(ForceType(), vm, 4)
- );
- return 0;
- }
+ template
+ struct HelperT {
+ static int SQCall(void *instance, Tretval (*func)(Targ1, Targ2, Targ3), HSQUIRRELVM vm)
+ {
+ (*func)(
+ GetParam(ForceType(), vm, 2),
+ GetParam(ForceType(), vm, 3),
+ GetParam(ForceType(), vm, 4)
+ );
+ return 0;
+ }
+ };
/**
- * The real C++ caller for method with a return value and 4 params.
+ * The real C++ caller for method with return value and 3 params.
*/
- template
- static int SQCall(CL *instance, RT (CL::*func)(P1, P2, P3, P4), HSQUIRRELVM vm)
- {
- return Return(vm, (instance->*func)(
- GetParam(ForceType(), vm, 2),
- GetParam(ForceType(), vm, 3),
- GetParam(ForceType(), vm, 4),
- GetParam(ForceType(), vm, 5)
- ));
- }
+ template
+ struct HelperT {
+ static int SQCall(Tcls *instance, Tretval (Tcls::*func)(Targ1, Targ2, Targ3), HSQUIRRELVM vm)
+ {
+ return Return(vm, (instance->*func)(
+ GetParam(ForceType(), vm, 2),
+ GetParam(ForceType(), vm, 3),
+ GetParam(ForceType(), vm, 4)
+ ));
+ }
+ };
/**
- * The real C++ caller for function with a return value and 4 params.
+ * The real C++ caller for method with no return value and 3 params.
*/
- template
- static int SQCall(CL *instance, RT (*func)(P1, P2, P3, P4), HSQUIRRELVM vm)
- {
- return Return(vm, (*func)(
- GetParam(ForceType(), vm, 2),
- GetParam(ForceType(), vm, 3),
- GetParam(ForceType(), vm, 4),
- GetParam(ForceType(), vm, 5)
- ));
- }
+ template
+ struct HelperT {
+ static int SQCall(Tcls *instance, Tretval (Tcls::*func)(Targ1, Targ2, Targ3), HSQUIRRELVM vm)
+ {
+ (instance->*func)(
+ GetParam(ForceType(), vm, 2),
+ GetParam(ForceType(), vm, 3),
+ GetParam(ForceType(), vm, 4)
+ );
+ return 0;
+ }
+ };
+
+ /**
+ * The real C++ caller for function with return value and 4 params.
+ */
+ template
+ struct HelperT {
+ static int SQCall(void *instance, Tretval (*func)(Targ1, Targ2, Targ3, Targ4), HSQUIRRELVM vm)
+ {
+ return Return(vm, (*func)(
+ GetParam(ForceType(), vm, 2),
+ GetParam(ForceType(), vm, 3),
+ GetParam(ForceType(), vm, 4),
+ GetParam(ForceType(), vm, 5)
+ ));
+ }
+ };
+
+ /**
+ * The real C++ caller for function with no return value and 4 params.
+ */
+ template
+ struct HelperT {
+ static int SQCall(void *instance, Tretval (*func)(Targ1, Targ2, Targ3, Targ4), HSQUIRRELVM vm)
+ {
+ (*func)(
+ GetParam(ForceType(), vm, 2),
+ GetParam(ForceType(), vm, 3),
+ GetParam(ForceType(), vm, 4),
+ GetParam(ForceType(), vm, 5)
+ );
+ return 0;
+ }
+ };
+
+ /**
+ * The real C++ caller for method with return value and 4 params.
+ */
+ template
+ struct HelperT {
+ static int SQCall(Tcls *instance, Tretval (Tcls::*func)(Targ1, Targ2, Targ3, Targ4), HSQUIRRELVM vm)
+ {
+ return Return(vm, (instance->*func)(
+ GetParam(ForceType(), vm, 2),
+ GetParam(ForceType(), vm, 3),
+ GetParam(ForceType(), vm, 4),
+ GetParam(ForceType(), vm, 5)
+ ));
+ }
+ };
/**
* The real C++ caller for method with no return value and 4 params.
*/
- template
- static int SQCall(CL *instance, void (CL::*func)(P1, P2, P3, P4), HSQUIRRELVM vm)
- {
- (instance->*func)(
- GetParam(ForceType(), vm, 2),
- GetParam(ForceType(), vm, 3),
- GetParam(ForceType(), vm, 4),
- GetParam(ForceType(), vm, 5)
- );
- return 0;
- }
+ template
+ struct HelperT {
+ static int SQCall(Tcls *instance, Tretval (Tcls::*func)(Targ1, Targ2, Targ3, Targ4), HSQUIRRELVM vm)
+ {
+ (instance->*func)(
+ GetParam(ForceType(), vm, 2),
+ GetParam(ForceType(), vm, 3),
+ GetParam(ForceType(), vm, 4),
+ GetParam(ForceType(), vm, 5)
+ );
+ return 0;
+ }
+ };
- /**
- * The real C++ caller for function with no return value and 4 params.
- */
- template
- static int SQCall(CL *instance, void (*func)(P1, P2, P3, P4), HSQUIRRELVM vm)
- {
- (*func)(
- GetParam(ForceType(), vm, 2),
- GetParam(ForceType(), vm, 3),
- GetParam(ForceType(), vm, 4),
- GetParam(ForceType(), 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.
*/
- template
- static SQInteger DefSQCallback(HSQUIRRELVM vm)
+ template
+ inline SQInteger DefSQCallback(HSQUIRRELVM vm)
{
/* Find the amount of params we got */
int nparam = sq_gettop(vm);
@@ -290,9 +385,10 @@
sq_getinstanceup(vm, 1, &instance, 0);
/* Get the real function pointer */
sq_getuserdata(vm, nparam, &ptr, 0);
- /* Deligate it to a template that can handle this specific function */
- return SQCall((CL *)instance, *(Func *)ptr, vm);
+ /* Delegate it to a template that can handle this specific function */
+ return HelperT::SQCall((Tcls *)instance, *(Tmethod *)ptr, vm);
}
-};
+
+}; // namespace SQConvert
#endif /* SQUIRREL_HELPER_HPP */