浏览代码

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.
 	// 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
 	// We have to specify which parameters our constructor takes, because there might be more than
 	// one constructor to deal with.
 	// 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
 	// Load Lua code
 	luaL_loadstring(
 	luaL_loadstring(

+ 6 - 0
lib/luwra/usertypes.hpp

@@ -329,6 +329,12 @@ template <typename T, typename... A>
 constexpr CFunction wrap_constructor =
 constexpr CFunction wrap_constructor =
 	&internal::construct_user_type<internal::StripUserType<T>, A...>;
 	&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:
  * 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
 	// Registration
 	luwra::register_user_type<A>(state);
 	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
 	// Construction
 	REQUIRE(luaL_dostring(state, "return A(73)") == 0);
 	REQUIRE(luaL_dostring(state, "return A(73)") == 0);