call.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2004-2005 by Reality Rift Studios                       *
00003  *   http://www.realityrift.com  -  mattias@realityrift.com                *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #ifndef neo_script_lua_call_h
00022 #define neo_script_lua_call_h
00023 
00029 #include "../../core/platform.h"
00030 
00031 #if NEO_ENABLE_SCRIPT_LUA
00032 
00033 #include "../../core/type.h"
00034 #include "reference.h"
00035 #include "conversion.h"
00036 
00037 extern "C" {
00038 
00039 #include "lua/lua.h"
00040     
00041 }
00042 
00043 namespace neo {
00044 namespace script {
00045 namespace lua {
00046 
00047 
00048 template < class R > struct Call
00049 {
00050     enum { isConst = core::TypeTraits< R >::isConst };
00051     
00052     template< class T, class P > static int call( lua_State* p_state, T* p_obj, R ( T::*f )(), P* )
00053     {
00054         Return< P >::push( p_state, (p_obj->*f)(), isConst );
00055         return 1;
00056     }
00057 
00058     template< class T, class P > static int call( lua_State* p_state, T* p_obj, R ( T::*f )() const, P* )
00059     {
00060         Return< P >::push( p_state, (p_obj->*f)(), isConst );
00061         return 1;
00062     }
00063 
00064     template< class T, class P, class A0 > static int call( lua_State* p_state, T* p_obj, R ( T::*f )( A0 ), P* )
00065     {
00066         Return< P >::push( p_state, (p_obj->*f)(
00067             Argument< typename core::TypeTraits< A0 >::NonConstReferredType >::get( p_state, 2 )
00068         ), isConst );
00069         return 1;
00070     }
00071 
00072     template< class T, class P, class A0 > static int call( lua_State* p_state, T* p_obj, R ( T::*f )( A0 ) const, P* )
00073     {
00074         Return< P >::push( p_state, (p_obj->*f)(
00075             Argument< typename core::TypeTraits< A0 >::NonConstReferredType >::get( p_state, 2 )
00076         ), isConst );
00077         return 1;
00078     }
00079 
00080     template< class T, class P, class A0, class A1 > static int call( lua_State* p_state, T* p_obj, R ( T::*f )( A0, A1 ), P* )
00081     {
00082         Return< P >::push( p_state, (p_obj->*f)(
00083             Argument< typename core::TypeTraits< A0 >::NonConstReferredType >::get( p_state, 2 ),
00084             Argument< typename core::TypeTraits< A1 >::NonConstReferredType >::get( p_state, 3 )
00085         ), isConst );
00086         return 1;
00087     }
00088 
00089     template< class T, class P, class A0, class A1 > static int call( lua_State* p_state, T* p_obj, R ( T::*f )( A0, A1 ) const, P* )
00090     {
00091         Return< P >::push( p_state, (p_obj->*f)(
00092             Argument< typename core::TypeTraits< A0 >::NonConstReferredType >::get( p_state, 2 ),
00093             Argument< typename core::TypeTraits< A1 >::NonConstReferredType >::get( p_state, 3 )
00094         ), isConst );
00095         return 1;
00096     }
00097 
00098     template< class T, class P, class A0, class A1, class A2 > static int call( lua_State* p_state, T* p_obj, R ( T::*f )( A0, A1, A2 ), P* )
00099     {
00100         Return< P >::push( p_state, (p_obj->*f)(
00101             Argument< typename core::TypeTraits< A0 >::NonConstReferredType >::get( p_state, 2 ),
00102             Argument< typename core::TypeTraits< A1 >::NonConstReferredType >::get( p_state, 3 ),
00103             Argument< typename core::TypeTraits< A2 >::NonConstReferredType >::get( p_state, 4 )
00104         ), isConst );
00105         return 1;
00106     }
00107 
00108     template< class T, class P, class A0, class A1, class A2 > static int call( lua_State* p_state, T* p_obj, R ( T::*f )( A0, A1, A2 ) const, P* )
00109     {
00110         Return< P >::push( p_state, (p_obj->*f)(
00111             Argument< typename core::TypeTraits< A0 >::NonConstReferredType >::get( p_state, 2 ),
00112             Argument< typename core::TypeTraits< A1 >::NonConstReferredType >::get( p_state, 3 ),
00113             Argument< typename core::TypeTraits< A2 >::NonConstReferredType >::get( p_state, 4 )
00114         ), isConst );
00115         return 1;
00116     }
00117 
00118     template< class T, class P, class A0, class A1, class A2, class A3 > static int call( lua_State* p_state, T* p_obj, R ( T::*f )( A0, A1, A2, A3 ), P* )
00119     {
00120         Return< P >::push( p_state, (p_obj->*f)(
00121             Argument< typename core::TypeTraits< A0 >::NonConstReferredType >::get( p_state, 2 ),
00122             Argument< typename core::TypeTraits< A1 >::NonConstReferredType >::get( p_state, 3 ),
00123             Argument< typename core::TypeTraits< A2 >::NonConstReferredType >::get( p_state, 4 ),
00124             Argument< typename core::TypeTraits< A3 >::NonConstReferredType >::get( p_state, 5 )
00125         ), isConst );
00126         return 1;
00127     }
00128 
00129     template< class T, class P, class A0, class A1, class A2, class A3 > static int call( lua_State* p_state, T* p_obj, R ( T::*f )( A0, A1, A2, A3 ) const, P* )
00130     {
00131         Return< P >::push( p_state, (p_obj->*f)(
00132             Argument< typename core::TypeTraits< A0 >::NonConstReferredType >::get( p_state, 2 ),
00133             Argument< typename core::TypeTraits< A1 >::NonConstReferredType >::get( p_state, 3 ),
00134             Argument< typename core::TypeTraits< A2 >::NonConstReferredType >::get( p_state, 4 ),
00135             Argument< typename core::TypeTraits< A3 >::NonConstReferredType >::get( p_state, 5 )
00136         ), isConst );
00137         return 1;
00138     }
00139 
00140     template< class P > static int call( lua_State* p_state, R ( *f )(), P* )
00141     {
00142         Return< P >::push( p_state, f(), isConst );
00143         return 1;
00144     }
00145 
00146     template< class P, class A0 > static int call( lua_State* p_state, R ( *f )( A0 ), P* )
00147     {
00148         Return< P >::push( p_state, f(
00149             Argument< typename core::TypeTraits< A0 >::NonConstReferredType >::get( p_state, 1 )
00150         ), isConst );
00151         return 1;
00152     }
00153 
00154     template< class P, class A0, class A1 > static int call( lua_State* p_state, R ( *f )( A0, A1 ), P* )
00155     {
00156         Return< P >::push( p_state, f(
00157             Argument< typename core::TypeTraits< A0 >::NonConstReferredType >::get( p_state, 1 ),
00158             Argument< typename core::TypeTraits< A1 >::NonConstReferredType >::get( p_state, 2 )
00159         ), isConst );
00160         return 1;
00161     }
00162 
00163     template< class P, class A0, class A1, class A2 > static int call( lua_State* p_state, R ( *f )( A0, A1, A2 ), P* )
00164     {
00165         Return< P >::push( p_state, f(
00166             Argument< typename core::TypeTraits< A0 >::NonConstReferredType >::get( p_state, 1 ),
00167             Argument< typename core::TypeTraits< A1 >::NonConstReferredType >::get( p_state, 2 ),
00168             Argument< typename core::TypeTraits< A2 >::NonConstReferredType >::get( p_state, 3 )
00169         ), isConst );
00170         return 1;
00171     }
00172 
00173     template< class P, class A0, class A1, class A2, class A3 > static int call( lua_State* p_state, R ( *f )( A0, A1, A2, A3 ), P* )
00174     {
00175         Return< P >::push( p_state, f(
00176             Argument< typename core::TypeTraits< A0 >::NonConstReferredType >::get( p_state, 1 ),
00177             Argument< typename core::TypeTraits< A1 >::NonConstReferredType >::get( p_state, 2 ),
00178             Argument< typename core::TypeTraits< A2 >::NonConstReferredType >::get( p_state, 3 ),
00179             Argument< typename core::TypeTraits< A3 >::NonConstReferredType >::get( p_state, 4 )
00180         ), isConst );
00181         return 1;
00182     }
00183 };
00184 
00185 template <> struct Call< void >
00186 {
00187     template < class T > static int call( lua_State*, T* p_obj, void ( T::*f )(), void* )
00188     {
00189         (p_obj->*f)();
00190         return 0;
00191     }
00192 
00193     template < class T > static int call( lua_State*, T* p_obj, void ( T::*f )() const, void* )
00194     {
00195         (p_obj->*f)();
00196         return 0;
00197     }
00198 
00199     template< class T, class A0 > static int call( lua_State* p_state, T* p_obj, void ( T::*f )( A0 ), void* )
00200     {
00201         (p_obj->*f)(
00202             Argument< typename core::TypeTraits< A0 >::NonConstReferredType >::get( p_state, 2 )
00203         );
00204         return 0;
00205     }
00206 
00207     template< class T, class A0 > static int call( lua_State* p_state, T* p_obj, void ( T::*f )( A0 ) const, void* )
00208     {
00209         (p_obj->*f)(
00210             Argument< typename core::TypeTraits< A0 >::NonConstReferredType >::get( p_state, 2 )
00211         );
00212         return 0;
00213     }
00214 
00215     template< class T, class A0, class A1 > static int call( lua_State* p_state, T* p_obj, void ( T::*f )( A0, A1 ), void* )
00216     {
00217         (p_obj->*f)(
00218             Argument< typename core::TypeTraits< A0 >::NonConstReferredType >::get( p_state, 2 ),
00219             Argument< typename core::TypeTraits< A1 >::NonConstReferredType >::get( p_state, 3 )
00220         );
00221         return 0;
00222     }
00223 
00224     template< class T, class A0, class A1 > static int call( lua_State* p_state, T* p_obj, void ( T::*f )( A0, A1 ) const, void* )
00225     {
00226         (p_obj->*f)(
00227             Argument< typename core::TypeTraits< A0 >::NonConstReferredType >::get( p_state, 2 ),
00228             Argument< typename core::TypeTraits< A1 >::NonConstReferredType >::get( p_state, 3 )
00229         );
00230         return 0;
00231     }
00232 
00233     template< class T, class A0, class A1, class A2 > static int call( lua_State* p_state, T* p_obj, void ( T::*f )( A0, A1, A2 ), void* )
00234     {
00235         (p_obj->*f)(
00236             Argument< typename core::TypeTraits< A0 >::NonConstReferredType >::get( p_state, 2 ),
00237             Argument< typename core::TypeTraits< A1 >::NonConstReferredType >::get( p_state, 3 ),
00238             Argument< typename core::TypeTraits< A2 >::NonConstReferredType >::get( p_state, 4 )
00239         );
00240         return 0;
00241     }
00242 
00243     template< class T, class A0, class A1, class A2 > static int call( lua_State* p_state, T* p_obj, void ( T::*f )( A0, A1, A2 ) const, void* )
00244     {
00245         (p_obj->*f)(
00246             Argument< typename core::TypeTraits< A0 >::NonConstReferredType >::get( p_state, 2 ),
00247             Argument< typename core::TypeTraits< A1 >::NonConstReferredType >::get( p_state, 3 ),
00248             Argument< typename core::TypeTraits< A2 >::NonConstReferredType >::get( p_state, 4 )
00249         );
00250         return 0;
00251     }
00252 
00253     template< class T, class A0, class A1, class A2, class A3 > static int call( lua_State* p_state, T* p_obj, void ( T::*f )( A0, A1, A2, A3 ), void* )
00254     {
00255         (p_obj->*f)(
00256             Argument< typename core::TypeTraits< A0 >::NonConstReferredType >::get( p_state, 2 ),
00257             Argument< typename core::TypeTraits< A1 >::NonConstReferredType >::get( p_state, 3 ),
00258             Argument< typename core::TypeTraits< A2 >::NonConstReferredType >::get( p_state, 4 ),
00259             Argument< typename core::TypeTraits< A3 >::NonConstReferredType >::get( p_state, 5 )
00260         );
00261         return 0;
00262     }
00263 
00264     template< class T, class A0, class A1, class A2, class A3 > static int call( lua_State* p_state, T* p_obj, void ( T::*f )( A0, A1, A2, A3 ) const, void* )
00265     {
00266         (p_obj->*f)(
00267             Argument< typename core::TypeTraits< A0 >::NonConstReferredType >::get( p_state, 2 ),
00268             Argument< typename core::TypeTraits< A1 >::NonConstReferredType >::get( p_state, 3 ),
00269             Argument< typename core::TypeTraits< A2 >::NonConstReferredType >::get( p_state, 4 ),
00270             Argument< typename core::TypeTraits< A3 >::NonConstReferredType >::get( p_state, 5 )
00271         );
00272         return 0;
00273     }
00274 
00275     static int call( lua_State*, void ( *f )(), void* )
00276     {
00277         f();
00278         return 0;
00279     }
00280 
00281     template< class A0 > static int call( lua_State* p_state, void ( *f )( A0 ), void* )
00282     {
00283         f(
00284             Argument< typename core::TypeTraits< A0 >::NonConstReferredType >::get( p_state, 2 )
00285         );
00286         return 0;
00287     }
00288 
00289     template< class A0, class A1 > static int call( lua_State* p_state, void ( *f )( A0, A1 ), void* )
00290     {
00291         f(
00292             Argument< typename core::TypeTraits< A0 >::NonConstReferredType >::get( p_state, 2 ),
00293             Argument< typename core::TypeTraits< A1 >::NonConstReferredType >::get( p_state, 3 )
00294         );
00295         return 0;
00296     }
00297 
00298     template< class A0, class A1, class A2 > static int call( lua_State* p_state, void ( *f )( A0, A1, A2 ), void* )
00299     {
00300         f(
00301             Argument< typename core::TypeTraits< A0 >::NonConstReferredType >::get( p_state, 2 ),
00302             Argument< typename core::TypeTraits< A1 >::NonConstReferredType >::get( p_state, 3 ),
00303             Argument< typename core::TypeTraits< A2 >::NonConstReferredType >::get( p_state, 4 )
00304         );
00305         return 0;
00306     }
00307 
00308     template< class A0, class A1, class A2, class A3 > static int call( lua_State* p_state, void ( *f )( A0, A1, A2, A3 ), void* )
00309     {
00310         f(
00311             Argument< typename core::TypeTraits< A0 >::NonConstReferredType >::get( p_state, 2 ),
00312             Argument< typename core::TypeTraits< A1 >::NonConstReferredType >::get( p_state, 3 ),
00313             Argument< typename core::TypeTraits< A2 >::NonConstReferredType >::get( p_state, 4 ),
00314             Argument< typename core::TypeTraits< A3 >::NonConstReferredType >::get( p_state, 5 )
00315         );
00316         return 0;
00317     }
00318 };
00319 
00320 
00321 template < class T, class R, class P > inline int call( lua_State* p_state, T* p_obj, R ( T::*f )(), P* p )
00322 {
00323     return Call< R >::call( p_state, p_obj, f, p );
00324 }
00325 
00326 
00327 template < class T, class R, class P > inline int call( lua_State* p_state, T* p_obj, R ( T::*f )() const, P* p )
00328 {
00329     return Call< R >::call( p_state, p_obj, f, p );
00330 }
00331 
00332 
00333 template < class T, class R, class P, class A0 > inline int call( lua_State* p_state, T* p_obj, R ( T::*f )( A0 ), P* p )
00334 {
00335     return Call< R >::call( p_state, p_obj, f, p );
00336 }
00337 
00338 
00339 template < class T, class R, class P, class A0 > inline int call( lua_State* p_state, T* p_obj, R ( T::*f )( A0 ) const, P* p )
00340 {
00341     return Call< R >::call( p_state, p_obj, f, p );
00342 }
00343 
00344 
00345 template < class T, class R, class P, class A0, class A1 > inline int call( lua_State* p_state, T* p_obj, R ( T::*f )( A0, A1 ), P* p )
00346 {
00347     return Call< R >::call( p_state, p_obj, f, p );
00348 }
00349 
00350 
00351 template < class T, class R, class P, class A0, class A1 > inline int call( lua_State* p_state, T* p_obj, R ( T::*f )( A0, A1 ) const, P* p )
00352 {
00353     return Call< R >::call( p_state, p_obj, f, p );
00354 }
00355 
00356 
00357 template < class T, class R, class P, class A0, class A1, class A2 > inline int call( lua_State* p_state, T* p_obj, R ( T::*f )( A0, A1, A2 ), P* p )
00358 {
00359     return Call< R >::call( p_state, p_obj, f, p );
00360 }
00361 
00362 
00363 template < class T, class R, class P, class A0, class A1, class A2 > inline int call( lua_State* p_state, T* p_obj, R ( T::*f )( A0, A1, A2 ) const, P* p )
00364 {
00365     return Call< R >::call( p_state, p_obj, f, p );
00366 }
00367 
00368 
00369 template < class T, class R, class P, class A0, class A1, class A2, class A3 > inline int call( lua_State* p_state, T* p_obj, R ( T::*f )( A0, A1, A2, A3 ), P* p )
00370 {
00371     return Call< R >::call( p_state, p_obj, f, p );
00372 }
00373 
00374 
00375 template < class T, class R, class P, class A0, class A1, class A2, class A3 > inline int call( lua_State* p_state, T* p_obj, R ( T::*f )( A0, A1, A2, A3 ) const, P* p )
00376 {
00377     return Call< R >::call( p_state, p_obj, f, p );
00378 }
00379 
00380 
00381 template < class R, class P > inline int call( lua_State* p_state, R ( *f )(), P* p )
00382 {
00383     return Call< R >::call( p_state, f, p );
00384 }
00385 
00386 
00387 template < class R, class P, class A0 > inline int call( lua_State* p_state, R ( *f )( A0 ), P* p )
00388 {
00389     return Call< R >::call( p_state, f, p );
00390 }
00391 
00392 
00393 template < class R, class P, class A0, class A1 > inline int call( lua_State* p_state, R ( *f )( A0, A1 ), P* p )
00394 {
00395     return Call< R >::call( p_state, f, p );
00396 }
00397 
00398 
00399 template < class R, class P, class A0, class A1, class A2 > inline int call( lua_State* p_state, R ( *f )( A0, A1, A2 ), P* p )
00400 {
00401     return Call< R >::call( p_state, f, p );
00402 }
00403 
00404 
00405 template < class R, class P, class A0, class A1, class A2, class A3 > inline int call( lua_State* p_state, R ( *f )( A0, A1, A2, A3 ), P* p )
00406 {
00407     return Call< R >::call( p_state, f, p );
00408 }
00409 
00410 
00411 }
00412 }
00413 }
00414 
00415 #endif
00416 
00417 #endif

Generated on Sat Feb 17 20:50:48 2007 for NeoEngine 2 - Evolution by  doxygen 1.5.1