Преглед на файлове

Every 'push' function return an unsigned integer

Ole преди 10 години
родител
ревизия
d1bcd32b0e
променени са 5 файла, в които са добавени 26 реда и са изтрити 39 реда
  1. 1 1
      examples/types.cpp
  2. 1 1
      examples/usertypes.cpp
  3. 4 4
      lib/luwra/stack.hpp
  4. 16 28
      lib/luwra/types.hpp
  5. 4 5
      lib/luwra/usertypes.hpp

+ 1 - 1
examples/types.cpp

@@ -25,7 +25,7 @@ namespace luwra {
 		 * push the value onto the stack.
 		 */
 		static inline
-		int push(lua_State* state, char val) {
+		size_t push(lua_State* state, char val) {
 			if (val == 0)
 				return 0;
 

+ 1 - 1
examples/usertypes.cpp

@@ -33,7 +33,7 @@ int main() {
 	// Register our user type.
 	// This function also registers a garbage-collector hook and a string representation function.
 	// Both can be overwritten using the third parameter, which lets you add custom meta methods.
-	luwra::registerUserType<Point(double, double)>(
+	luwra::registerUserType<Point (double, double)>(
 		state,
 		// Constructor name
 		"Point",

+ 4 - 4
lib/luwra/stack.hpp

@@ -153,7 +153,7 @@ namespace internal {
 	template <typename... A>
 	struct LayoutMapper<void (A...)> {
 		template <typename F, typename... X> static inline
-		int map(State* state, int n, F&& hook, X&&... args) {
+		size_t map(State* state, int n, F&& hook, X&&... args) {
 			direct<void (A...)>(
 				state,
 				n,
@@ -167,7 +167,7 @@ namespace internal {
 	template <typename R, typename... A>
 	struct LayoutMapper<R (A...)> {
 		template <typename F, typename... X> static inline
-		int map(State* state, int n, F&& hook, X&&... args) {
+		size_t map(State* state, int n, F&& hook, X&&... args) {
 			return push(
 				state,
 				direct<R (A...)>(
@@ -186,7 +186,7 @@ namespace internal {
  * \returns Number of values pushed
  */
 template <typename S, typename F, typename... A> static inline
-int map(State* state, int pos, F&& hook, A&&... args) {
+size_t map(State* state, int pos, F&& hook, A&&... args) {
 	return internal::LayoutMapper<S>::map(
 		state,
 		pos,
@@ -199,7 +199,7 @@ int map(State* state, int pos, F&& hook, A&&... args) {
  * Same as `map(state, 1, hook)`.
  */
 template <typename S, typename F, typename... A> static inline
-int map(State* state, F&& hook, A&&... args) {
+size_t map(State* state, F&& hook, A&&... args) {
 	return internal::LayoutMapper<S>::map(
 		state,
 		1,

+ 16 - 28
lib/luwra/types.hpp

@@ -52,7 +52,7 @@ struct Value {
 	 * \returns Number of values pushed
 	 */
 	static
-	int push(State* state, T value);
+	size_t push(State* state, T value);
 };
 
 // Nil
@@ -65,7 +65,7 @@ struct Value<std::nullptr_t> {
 	}
 
 	static inline
-	int push(State* state, std::nullptr_t) {
+	size_t push(State* state, std::nullptr_t) {
 		lua_pushnil(state);
 		return 1;
 	}
@@ -75,7 +75,7 @@ struct Value<std::nullptr_t> {
  * Convenient wrapped for [Value<T>::push](@ref Value<T>::push).
  */
 template <typename T> static inline
-int push(State* state, T value) {
+size_t push(State* state, T value) {
 	return Value<T>::push(state, value);
 }
 
@@ -83,20 +83,8 @@ int push(State* state, T value) {
  * Allows you to push multiple values at once.
  */
 template <typename T1, typename T2, typename... TR>
-int push(State* state, T1 value, T2&& head, TR&&... rest) {
-	int result = push(state, value);
-
-	if (result < 0)
-		return result;
-
-	int other = push(state, std::forward<T2>(head), std::forward<TR>(rest)...);
-
-	if (other < 0) {
-		lua_pop(state, result);
-		return other;
-	} else {
-		return result + other;
-	}
+size_t push(State* state, T1 value, T2&& head, TR&&... rest) {
+	return push(state, value) + push(state, std::forward<T2>(head), std::forward<TR>(rest)...);
 }
 
 /**
@@ -121,7 +109,7 @@ T read(State* state, int index) {
 		}                                                            \
                                                                      \
 		static inline                                                \
-		int push(State* state, type value) {                         \
+		size_t push(State* state, type value) {                      \
 			pushf(state, value);                                     \
 			return 1;                                                \
 		}                                                            \
@@ -169,7 +157,7 @@ namespace internal {
 		}
 
 		static inline
-		int push(State* state, Integer value) {
+		size_t push(State* state, Integer value) {
 			lua_pushinteger(state, value);
 			return 1;
 		}
@@ -184,7 +172,7 @@ namespace internal {
 		}
 
 		static inline
-		int push(State* state, Number value) {
+		size_t push(State* state, Number value) {
 			lua_pushnumber(state, value);
 			return 1;
 		}
@@ -207,7 +195,7 @@ namespace internal {
 		}
 
 		static inline
-		int push(State* state, I value) {
+		size_t push(State* state, I value) {
 			NumericTransportValue<B>::push(state, static_cast<B>(value));
 			return 1;
 		}
@@ -223,7 +211,7 @@ namespace internal {
 		}
 
 		static inline
-		int push(State*, I) {
+		size_t push(State*, I) {
 			static_assert(
 				sizeof(I) == -1,
 				"You must not use 'Value<I>::push' specializations which inherit from NumericTruncatingValueBase"
@@ -294,7 +282,7 @@ struct Value<const char[n]>: Value<const char*> {};
 template <>
 struct Value<CFunction> {
 	static inline
-	int push(State* state, CFunction fun) {
+	size_t push(State* state, CFunction fun) {
 		lua_pushcfunction(state, fun);
 		return 1;
 	}
@@ -320,7 +308,7 @@ struct Value<Arbitrary> {
 	}
 
 	static inline
-	int push(State* state, const Arbitrary& value) {
+	size_t push(State* state, const Arbitrary& value) {
 		lua_pushvalue(value.state, value.index);
 
 		if (value.state != state)
@@ -337,16 +325,16 @@ namespace internal {
 	template <size_t I>
 	struct StackPusher<std::index_sequence<I>> {
 		template <typename... T> static inline
-		int push(State* state, const std::tuple<T...>& package) {
+		size_t push(State* state, const std::tuple<T...>& package) {
 			using R = typename std::tuple_element<I, std::tuple<T...>>::type;
-			return std::max(0, Value<R>::push(state, std::get<I>(package)));
+			return Value<R>::push(state, std::get<I>(package));
 		}
 	};
 
 	template <size_t I, size_t... Is>
 	struct StackPusher<std::index_sequence<I, Is...>> {
 		template <typename... T> static inline
-		int push(State* state, const std::tuple<T...>& package) {
+		size_t push(State* state, const std::tuple<T...>& package) {
 			return
 				StackPusher<std::index_sequence<I>>::push(state, package)
 				+ StackPusher<std::index_sequence<Is...>>::push(state, package);
@@ -360,7 +348,7 @@ namespace internal {
 template <typename... A>
 struct Value<std::tuple<A...>> {
 	static inline
-	int push(State* state, const std::tuple<A...>& value) {
+	size_t push(State* state, const std::tuple<A...>& value) {
 		return internal::StackPusher<std::make_index_sequence<sizeof...(A)>>::push(state, value);
 	}
 };

+ 4 - 5
lib/luwra/usertypes.hpp

@@ -50,7 +50,6 @@ namespace internal {
 	template <typename U> static inline
 	StripUserType<U>* check_user_type(State* state, int index) {
 		using T = StripUserType<U>;
-
 		return static_cast<T*>(luaL_checkudata(state, index, user_type_reg_name<T>.c_str()));
 	}
 
@@ -70,7 +69,7 @@ namespace internal {
 	 */
 	template <typename U, typename... A> static inline
 	int construct_user_type(State* state) {
-		return direct<int(A...)>(
+		return direct<size_t (A...)>(
 			state,
 			&Value<StripUserType<U>&>::template push<A...>,
 			state
@@ -123,7 +122,7 @@ struct Value<U&> {
 	}
 
 	template <typename... A> static inline
-	int push(State* state, A&&... args) {
+	size_t push(State* state, A&&... args) {
 		void* mem = lua_newuserdata(state, sizeof(T));
 
 		if (!mem) {
@@ -157,7 +156,7 @@ struct Value<U*> {
 	}
 
 	static inline
-	int push(State* state, T* instance) {
+	size_t push(State* state, T* instance) {
 		if (instance == nullptr)
 			return 0;
 
@@ -238,7 +237,7 @@ namespace internal {
 	};
 
 	template <typename T, typename... A>
-	struct UserTypeSignature<T(A...)> {
+	struct UserTypeSignature<T (A...)> {
 		using UserType = T;
 
 		static inline