Bläddra i källkod

Add several constants to make user type member binding easier

Ole 10 år sedan
förälder
incheckning
61573adc6b
2 ändrade filer med 9 tillägg och 5 borttagningar
  1. 5 5
      examples/usertypes.cpp
  2. 4 0
      lib/luwra/usertypes.hpp

+ 5 - 5
examples/usertypes.cpp

@@ -21,7 +21,7 @@ struct Point {
 		y *= f;
 	}
 
-	std::string toString() const {
+	std::string __tostring() const {
 		return "<Point(" + std::to_string(x) + ", " + std::to_string(y) + ")>";
 	}
 };
@@ -37,13 +37,13 @@ int main() {
 		state,
 		// Methods which shall be availabe in the Lua user data, need to be declared here
 		{
-			{"scale", LUWRA_WRAP_METHOD(Point::scale)},
-			{"x",     LUWRA_WRAP_FIELD(Point::x)},
-			{"y",     LUWRA_WRAP_FIELD(Point::y)}
+			LUWRA_METHOD(Point, scale),
+			LUWRA_FIELD(Point, x),
+			LUWRA_FIELD(Point, y)
 		},
 		// Meta methods may be registered aswell
 		{
-			{"__tostring", LUWRA_WRAP_METHOD(Point::toString)}
+			LUWRA_METHOD(Point, __tostring)
 		}
 	);
 

+ 4 - 0
lib/luwra/usertypes.hpp

@@ -229,4 +229,8 @@ LUWRA_NS_END
 #define LUWRA_WRAP_CONSTRUCTOR(type, ...) \
 	(&luwra::internal::construct_user_type<luwra::internal::StripUserType<type>, __VA_ARGS__>)
 
+#define LUWRA_FIELD(type, name) {__STRING(name), LUWRA_WRAP_FIELD(type::name)}
+#define LUWRA_METHOD(type, name) {__STRING(name), LUWRA_WRAP_METHOD(type::name)}
+#define LUWRA_FUNCTION(type, name) {__STRING(name), LUWRA_WRAP_FUNCTION(type::name)}
+
 #endif