Ver código fonte

Convert constructor lambda to std::function

Ole Krüger 10 anos atrás
pai
commit
fe674438cb
1 arquivos alterados com 25 adições e 25 exclusões
  1. 25 25
      lib/luwra/userdata.hpp

+ 25 - 25
lib/luwra/userdata.hpp

@@ -16,31 +16,6 @@
 
 LUWRA_NS_BEGIN
 
-namespace internal {
-	template <typename T, typename... A>
-	int userdata_ctor(State* state) {
-		return apply(state, [state](A... args) {
-			return Value<T>::push(state, args...);
-		});
-	}
-
-	template <typename T>
-	int userdata_dtor(State* state) {
-		Value<T*>::read(state, 1)->~T();
-		return 0;
-	}
-
-	template <typename T>
-	int userdata_tostring(State* state) {
-		T* instance = Value<T*>::read(state, 1);
-
-		return Value<std::string>::push(
-			state,
-			std::string(T::MetatableName) + ": #" + std::to_string(uintmax_t(instance))
-		);
-	}
-}
-
 /**
  * Instances of userdata shall always be used as pointers, because other Lua types can not be
  * converted to pointers, hence this allows the compiler to differentiate between them.
@@ -74,6 +49,31 @@ struct Value<T*> {
 	}
 };
 
+namespace internal {
+	template <typename T, typename... A>
+	int userdata_ctor(State* state) {
+		return apply(state, std::function<int(A...)>([state](A... args) {
+			return Value<T*>::push(state, args...);
+		}));
+	}
+
+	template <typename T>
+	int userdata_dtor(State* state) {
+		Value<T*>::read(state, 1)->~T();
+		return 0;
+	}
+
+	template <typename T>
+	int userdata_tostring(State* state) {
+		T* instance = Value<T*>::read(state, 1);
+
+		return Value<std::string>::push(
+			state,
+			std::string(T::MetatableName) + ": #" + std::to_string(uintmax_t(instance))
+		);
+	}
+}
+
 /**
  * Generate the metatable for the userdata type `T`. This function allows you to register methods
  * which are shared across all instances of this type. A garbage-collector hook is also inserted;