瀏覽代碼

Simplify FunctionWrapper and Layout

Ole 10 年之前
父節點
當前提交
286a5d3d4f
共有 2 個文件被更改,包括 10 次插入33 次删除
  1. 0 33
      lib/luwra/functions.hpp
  2. 10 0
      lib/luwra/stack.hpp

+ 0 - 33
lib/luwra/functions.hpp

@@ -22,23 +22,6 @@ namespace internal {
 		);
 	};
 
-	template <>
-	struct FunctionWrapper<void()> {
-		template <void(*function_pointer)()> static inline
-		int invoke(State*) {
-			function_pointer();
-			return 0;
-		}
-	};
-
-	template <typename R>
-	struct FunctionWrapper<R()> {
-		template <R(*function_pointer)()> static inline
-		int invoke(State* state) {
-			return push(state, function_pointer());
-		}
-	};
-
 	template <typename... A>
 	struct FunctionWrapper<void(A...)> {
 		template <void (*function_pointer)(A...)> static inline
@@ -73,19 +56,6 @@ namespace internal {
 	};
 }
 
-/**
- * Assuming its parameters can be retrieved from the Lua stack, ordinary functions can be wrapped
- * using the `wrap_function` instance in order to produce a C function which can be used by the
- * Lua VM.
- *
- * Assuming your function has the following signature:
- *
- *   R my_fun(A0, A1 ... An);
- *
- * Generate a Lua-compatible like so:
- *
- *   CFunction wrapped_fun = wrap_function<R(A0, A1 ... An), my_fun>;
- */
 template <
 	typename S,
 	S* function_pointer
@@ -93,9 +63,6 @@ template <
 constexpr CFunction wrap_function =
 	&internal::FunctionWrapper<S>::template invoke<function_pointer>;
 
-/**
- * This macros allows you to wrap functions without providing a type signature.
- */
 #define LUWRA_WRAP_FUNCTION(fun) \
 	(luwra::wrap_function< \
 	     typename luwra::internal::FunctionWrapperHelper<decltype(&fun)>::Signature, \

+ 10 - 0
lib/luwra/stack.hpp

@@ -26,6 +26,16 @@ namespace internal {
 		);
 	};
 
+	template <typename R>
+	struct Layout<R()> {
+		template <typename F, typename... A> static inline
+		R direct(State*, int, F hook, A&&... args) {
+			return hook(
+				std::forward<A>(args)...
+			);
+		}
+	};
+
 	template <typename R, typename T>
 	struct Layout<R(T)> {
 		template <typename F, typename... A> static inline