소스 검색

Add macro for constructor wrapping

Ole 10 년 전
부모
커밋
54f0a09f1d
3개의 변경된 파일8개의 추가작업 그리고 2개의 파일을 삭제
  1. 1 1
      examples/usertypes.cpp
  2. 6 0
      lib/luwra/usertypes.hpp
  3. 1 1
      tests/usertypes.cpp

+ 1 - 1
examples/usertypes.cpp

@@ -50,7 +50,7 @@ int main() {
 	// What's left, is registering a constructor for our type.
 	// We have to specify which parameters our constructor takes, because there might be more than
 	// one constructor to deal with.
-	luwra::register_global(state, "Point", luwra::wrap_constructor<Point, double, double>);
+	luwra::register_global(state, "Point", LUWRA_WRAP_CONSTRUCTOR(Point, double, double));
 
 	// Load Lua code
 	luaL_loadstring(

+ 6 - 0
lib/luwra/usertypes.hpp

@@ -329,6 +329,12 @@ template <typename T, typename... A>
 constexpr CFunction wrap_constructor =
 	&internal::construct_user_type<internal::StripUserType<T>, A...>;
 
+/**
+ * This macros has no additional use whatsoever, but I makes the style consistent.
+ */
+#define LUWRA_WRAP_CONSTRUCTOR(type, ...) \
+	(luwra::wrap_constructor<type, __VA_ARGS__>)
+
 /**
  * Works similiar to `wrap_function`. Given a class or struct declaration as follows:
  *

+ 1 - 1
tests/usertypes.cpp

@@ -34,7 +34,7 @@ TEST_CASE("usertypes_ctor") {
 
 	// Registration
 	luwra::register_user_type<A>(state);
-	luwra::register_global(state, "A", luwra::wrap_constructor<A, int>);
+	luwra::register_global(state, "A", LUWRA_WRAP_CONSTRUCTOR(A, int));
 
 	// Construction
 	REQUIRE(luaL_dostring(state, "return A(73)") == 0);