src/squirrel_helper.hpp
branchnoai
changeset 9437 28e0105114a4
parent 9434 2e71647c2c1c
child 9480 d071f885f918
equal deleted inserted replaced
9436:e28503f827a5 9437:28e0105114a4
    35 	{
    35 	{
    36 		return Return(vm, (instance->*func)());
    36 		return Return(vm, (instance->*func)());
    37 	}
    37 	}
    38 
    38 
    39 	/**
    39 	/**
       
    40 	 * The real C++ caller for function with no return value and 0 params.
       
    41 	 */
       
    42 	template <typename CL>
       
    43 	static int SQCall(CL *instance, void (CL::*func)(), HSQUIRRELVM vm)
       
    44 	{
       
    45 		(instance->*func)();
       
    46 		return 0;
       
    47 	}
       
    48 
       
    49 	/**
    40 	 * The real C++ caller for function with a return value and 1 param.
    50 	 * The real C++ caller for function with a return value and 1 param.
    41 	 */
    51 	 */
    42 	template <typename CL, typename RT, typename P1>
    52 	template <typename CL, typename RT, typename P1>
    43 	static int SQCall(CL *instance, RT (CL::*func)(P1), HSQUIRRELVM vm)
    53 	static int SQCall(CL *instance, RT (CL::*func)(P1), HSQUIRRELVM vm)
    44 	{
    54 	{
    45 		return Return(vm, (instance->*func)(
    55 		return Return(vm, (instance->*func)(
    46 						GetParam(ForceType<P1>(), vm, 2)
    56 						GetParam(ForceType<P1>(), vm, 2)
    47 					));
    57 					));
       
    58 	}
       
    59 
       
    60 	/**
       
    61 	 * The real C++ caller for function with no return value and 1 param.
       
    62 	 */
       
    63 	template <typename CL, typename P1>
       
    64 	static int SQCall(CL *instance, void (CL::*func)(P1), HSQUIRRELVM vm)
       
    65 	{
       
    66 		(instance->*func)(
       
    67 						GetParam(ForceType<P1>(), vm, 2)
       
    68 					);
       
    69 		return 0;
    48 	}
    70 	}
    49 
    71 
    50 	/**
    72 	/**
    51 	 * The real C++ caller for function with a return value and 2 params.
    73 	 * The real C++ caller for function with a return value and 2 params.
    52 	 */
    74 	 */
    58 						GetParam(ForceType<P2>(), vm, 3)
    80 						GetParam(ForceType<P2>(), vm, 3)
    59 					));
    81 					));
    60 	}
    82 	}
    61 
    83 
    62 	/**
    84 	/**
       
    85 	 * The real C++ caller for function with no return value and 2 params.
       
    86 	 */
       
    87 	template <typename CL, typename P1, typename P2>
       
    88 	static int SQCall(CL *instance, void (CL::*func)(P1, P2), HSQUIRRELVM vm)
       
    89 	{
       
    90 		(instance->*func)(
       
    91 						GetParam(ForceType<P1>(), vm, 2),
       
    92 						GetParam(ForceType<P2>(), vm, 3)
       
    93 					);
       
    94 		return 0;
       
    95 	}
       
    96 
       
    97 	/**
    63 	 * The real C++ caller for function with a return value and 3 params.
    98 	 * The real C++ caller for function with a return value and 3 params.
    64 	 */
    99 	 */
    65 	template <typename CL, typename RT, typename P1, typename P2, typename P3>
   100 	template <typename CL, typename RT, typename P1, typename P2, typename P3>
    66 	static int SQCall(CL *instance, RT (CL::*func)(P1, P2, P3), HSQUIRRELVM vm)
   101 	static int SQCall(CL *instance, RT (CL::*func)(P1, P2, P3), HSQUIRRELVM vm)
    67 	{
   102 	{
    68 		return Return(vm, (instance->*func)(
   103 		return Return(vm, (instance->*func)(
    69 						GetParam(ForceType<P1>(), vm, 2),
   104 						GetParam(ForceType<P1>(), vm, 2),
    70 						GetParam(ForceType<P2>(), vm, 3),
   105 						GetParam(ForceType<P2>(), vm, 3),
    71 						GetParam(ForceType<P3>(), vm, 4)
   106 						GetParam(ForceType<P3>(), vm, 4)
    72 					));
   107 					));
       
   108 	}
       
   109 
       
   110 	/**
       
   111 	 * The real C++ caller for function with no return value and 3 params.
       
   112 	 */
       
   113 	template <typename CL, typename P1, typename P2, typename P3>
       
   114 	static int SQCall(CL *instance, void (CL::*func)(P1, P2, P3), HSQUIRRELVM vm)
       
   115 	{
       
   116 		(instance->*func)(
       
   117 						GetParam(ForceType<P1>(), vm, 2),
       
   118 						GetParam(ForceType<P2>(), vm, 3),
       
   119 						GetParam(ForceType<P3>(), vm, 4)
       
   120 					);
       
   121 		return 0;
    73 	}
   122 	}
    74 
   123 
    75 	/**
   124 	/**
    76 	 * A general template for all callback functions from Squirrel.
   125 	 * A general template for all callback functions from Squirrel.
    77 	 *  In here the function_proc is recovered, and the SQCall is called that
   126 	 *  In here the function_proc is recovered, and the SQCall is called that