Index: trunk/nv/lua/lua_dispatch.hh
===================================================================
--- trunk/nv/lua/lua_dispatch.hh	(revision 319)
+++ trunk/nv/lua/lua_dispatch.hh	(revision 345)
@@ -29,117 +29,80 @@
 		namespace detail
 		{
+			template <typename...>
+			struct types {};
+
 			template < typename R >
-			struct dispatcher
+			struct call_and_push
 			{
-				static int call( lua_State* L, int, R (*func)() )
+				template <typename... Args, typename... Vs>
+				static void do_call(lua_State* L, R(*func)(Args...), Vs&&... vs)
 				{
-					push_value( L, func() ); return 1;
+					push_value(L, func(std::forward<Vs>(vs)...)); 
 				}
-				template < typename T1 >
-				static int call( lua_State* L, int index, R (*func)( T1 ) )
+				template <class C, typename... Args, typename... Vs>
+				static void do_call(lua_State* L, C& c, R(C::*func)(Args...), Vs&&... vs)
 				{
-					push_value( L, func( get_value<T1>( L, index + 0 ) ) ); return 1;
-				}
-				template < typename T1, typename T2 >
-				static int call( lua_State* L, int index, R (*func)( T1, T2 ) )
-				{
-					push_value( L, func( get_value<T1>( L, index + 0 ),	get_value<T2>( L, index + 1 ) ) ); return 1;
-				}
-				template < typename T1, typename T2, typename T3 >
-				static int call( lua_State* L, int index, R (*func)( T1, T2, T3 ) )
-				{
-					push_value( L, func( get_value<T1>( L, index + 0 ), get_value<T2>( L, index + 1 ), get_value<T3>( L, index + 2 ) ) ); return 1;
-				}
-				template < typename T1, typename T2, typename T3, typename T4 >
-				static int call( lua_State* L, int index, R (*func)( T1, T2, T3, T4 ) )
-				{
-					push_value( L, func( get_value<T1>( L, index + 0 ), get_value<T2>( L, index + 1 ), get_value<T3>( L, index + 2 ), get_value<T4>( L, index + 3 ) ) ); return 1;
-				}
-				template < class C >
-				static int call( lua_State* L, int, C& c, R (C::*func)() )
-				{
-					push_value( L, (c.*func)() ); return 1;
-				}
-				template < class C, typename T1 >
-				static int call( lua_State* L, int index, C& c, R (C::*func)( T1 ) )
-				{
-					push_value( L, (c.*func)( get_value<T1>( L, index + 0 ) ) ); return 1;
-				}
-				template < class C, typename T1, typename T2 >
-				static int call( lua_State* L, int index, C& c, R (C::*func)( T1, T2 ) )
-				{
-					push_value( L, (c.*func)( get_value<T1>( L, index + 0 ),	get_value<T2>( L, index + 1 ) ) ); return 1;
-				}
-				template < class C, typename T1, typename T2, typename T3 >
-				static int call( lua_State* L, int index, C& c, R (C::*func)( T1, T2, T3 ) )
-				{
-					push_value( L, (c.*func)( get_value<T1>( L, index + 0 ), get_value<T2>( L, index + 1 ), get_value<T3>( L, index + 2 ) ) ); return 1;
-				}
-				template < class C, typename T1, typename T2, typename T3, typename T4 >
-				static int call( lua_State* L, int index, C& c, R (C::*func)( T1, T2, T3, T4 ) )
-				{
-					push_value( L, (c.*func)( get_value<T1>( L, index + 0 ), get_value<T2>( L, index + 1 ), get_value<T3>( L, index + 2 ), get_value<T4>( L, index + 3 ) ) ); return 1;
+					push_value(L, (c.*func)(std::forward<Vs>(vs)...)); 
 				}
 			};
-			
+
 			template <>
-			struct dispatcher< void >
+			struct call_and_push<void>
 			{
-				static int call( lua_State*, int, void (*func)() )
+				template <typename... Args, typename... Vs>
+				static void do_call(lua_State*, void(*func)(Args...), Vs&&... vs)
 				{
-					func(); return 0;
+					func(std::forward<Vs>(vs)...);
 				}
-				template < typename T1 >
-				static int call( lua_State* L, int index, void (*func)( T1 ) )
+				template <class C, typename... Args, typename... Vs>
+				static void do_call(lua_State*, C& c, void(C::*func)(Args...), Vs&&... vs)
 				{
-					func( get_value<T1>( L, index + 0 ) ); return 0;
+					(c.*func)(std::forward<Vs>(vs)...);
 				}
-				template < typename T1, typename T2 >
-				static int call( lua_State* L, int index, void (*func)( T1, T2 ) )
-				{
-					func( get_value<T1>( L, index + 0 ), get_value<T2>( L, index + 1 ) ); return 0;
-				}
-				template < typename T1, typename T2, typename T3 >
-				static int call( lua_State* L, int index, void (*func)( T1, T2, T3 ) )
-				{
-					func( get_value<T1>( L, index + 0 ), get_value<T2>( L, index + 1 ), get_value<T3>( L, index + 2 ) ); return 0;
-				}
-				template < typename T1, typename T2, typename T3, typename T4 >
-				static int call( lua_State* L, int index, void (*func)( T1, T2, T3, T4 ) )
-				{
-					func( get_value<T1>( L, index + 0 ), get_value<T2>( L, index + 1 ), get_value<T3>( L, index + 2 ), get_value<T4>( L, index + 3 ) ); return 0;
-				}
-				template < class C >
-				static int call( lua_State*, int, C& c, void (C::*func)() )
-				{
-					(c.*func)(); return 0;
-				}
-				template < class C, typename T1 >
-				static int call( lua_State* L, int index, C& c, void (C::*func)( T1 ) )
-				{
-					(c.*func)( get_value<T1>( L, index + 0 ) ); return 0;
-				}
-				template < class C, typename T1, typename T2 >
-				static int call( lua_State* L, int index, C& c, void (C::*func)( T1, T2 ) )
-				{
-					(c.*func)( get_value<T1>( L, index + 0 ),	get_value<T2>( L, index + 1 ) ); return 0;
-				}
-				template < class C, typename T1, typename T2, typename T3 >
-				static int call( lua_State* L, int index, C& c, void (C::*func)( T1, T2, T3 ) )
-				{
-					(c.*func)( get_value<T1>( L, index + 0 ), get_value<T2>( L, index + 1 ), get_value<T3>( L, index + 2 ) ); return 0;
-				}
-				template < class C, typename T1, typename T2, typename T3, typename T4 >
-				static int call( lua_State* L, int index, C& c, void (C::*func)( T1, T2, T3, T4 ) )
-				{
-					(c.*func)( get_value<T1>( L, index + 0 ), get_value<T2>( L, index + 1 ), get_value<T3>( L, index + 2 ), get_value<T4>( L, index + 3 ) ); return 0;
-				}
+			};
 
-			};
+			template <typename R, typename... Args, typename Head, typename ...Tail, typename... Vs>
+			int do_call(lua_State* L, int index, R(*func)(Args...), types<Head, Tail...>, Vs&&... vs)
+			{
+				do_call(L, index + 1, func, types < Tail... > {}, std::forward<Vs>(vs)..., get_value<Head>(L, index)); return 1;
+			}
+
+			template <typename R, class C, typename... Args, typename Head, typename ...Tail, typename... Vs>
+			int do_call(lua_State* L, int index, C& c, R(C::*func)(Args...), types<Head, Tail...>, Vs&&... vs)
+			{
+				do_call(L, index + 1, c, func, types < Tail... > {}, std::forward<Vs>(vs)..., get_value<Head>(L, index)); return 1;
+			}
+
+			template <typename R, typename... Args, typename... Vs>
+			int do_call(lua_State* L, int, R(*func)(Args...), types<>, Vs&&... vs)
+			{
+				call_and_push<R>::do_call(L, func, std::forward<Vs>(vs)...);
+				return 1;
+			}
+
+			template <typename R, class C, typename... Args, typename... Vs>
+			int do_call(lua_State* L, int, C& c, R(C::*func)(Args...), types<>, Vs&&... vs)
+			{
+				call_and_push<R>::do_call(L, c, func, std::forward<Vs>(vs)...);
+				return 1;
+			}
+
+			template < typename R, typename... Args >
+			int dispatch(lua_State* L, int index, R(*func)(Args...))
+			{
+				do_call(L, index, func, types < Args... > {});
+				return 1;
+			}
+			template < typename R, class C, typename... Args >
+			int dispatch(lua_State* L, int index, C& c, R(C::*func)(Args...))
+			{
+				do_call(L, index, c, func, types < Args... > {});
+				return 1;
+			}
 
 			template < typename F, F f > 
 			int function_wrapper( lua_State* L ) 
 			{
-				return dispatcher<typename return_type<F>::type>::call( L, 1, f );
+				return dispatch(L, 1, f);
 			}
 
@@ -148,5 +111,5 @@
 			{
 				C* c = (C*)to_ref_object( L, 1 );
-				return dispatcher<typename return_type<F>::type>::call( L, 2, *c, f );
+				return dispatch( L, 2, *c, f );
 			}
 
@@ -155,19 +118,7 @@
 			{
 				C* c = (C*)to_pointer( L, nv::lua::detail::upvalue_index(1) );
-				return dispatcher<typename return_type<F>::type>::call( L, 1, *c, f );
+				return dispatch( L, 1, *c, f );
 			}
 			
-			template< typename F >
-			int call( lua_State* L, int index, F func )
-			{
-				return dispatcher<typename return_type<F>::type>::call( L, index, func );
-			}
-
-			template< class C, typename F >
-			int call( lua_State* L, int index, C& c, F func )
-			{
-				return dispatcher<typename return_type<F>::type>::call( L, index, c, func );
-			}
-
 		}
 
