Sfoglia il codice sorgente

Move auxiliary functions to auxiliary.hpp

Ole 10 anni fa
parent
commit
6597a39b6e
4 ha cambiato i file con 71 aggiunte e 53 eliminazioni
  1. 1 0
      lib/luwra.hpp
  2. 69 0
      lib/luwra/auxiliary.hpp
  3. 0 52
      lib/luwra/stack.hpp
  4. 1 1
      lib/luwra/state.hpp

+ 1 - 0
lib/luwra.hpp

@@ -4,6 +4,7 @@
 #include "luwra/common.hpp"
 #include "luwra/types.hpp"
 #include "luwra/stack.hpp"
+#include "luwra/auxiliary.hpp"
 #include "luwra/functions.hpp"
 #include "luwra/methods.hpp"
 #include "luwra/fields.hpp"

+ 69 - 0
lib/luwra/auxiliary.hpp

@@ -0,0 +1,69 @@
+/* Luwra
+ * Minimal-overhead Lua wrapper for C++
+ *
+ * Copyright (C) 2015, Ole Krüger <ole@vprsm.de>
+ */
+
+#ifndef LUWRA_AUXILIARY_H_
+#define LUWRA_AUXILIARY_H_
+
+#include "common.hpp"
+#include "types.hpp"
+
+LUWRA_NS_BEGIN
+
+/**
+ * Check if two values are equal.
+ */
+static inline
+bool equal(State* state, int index1, int index2) {
+#if LUA_VERSION_NUM <= 501
+	return lua_equal(state, index1, index2);
+#else
+	return lua_compare(state, index1, index2, LUA_OPEQ);
+#endif
+}
+
+/**
+ * Register a value as a global.
+ */
+template <typename V> static inline
+void setGlobal(State* state, const std::string& name, V value) {
+	assert(1 == push(state, value));
+	lua_setglobal(state, name.c_str());
+}
+
+/**
+ * Retrieve a global value.
+ */
+template <typename V> static inline
+V getGlobal(State* state, const std::string& name) {
+	lua_getglobal(state, name.c_str());
+
+	V instance = read<V>(state, -1);
+	lua_pop(state, 1);
+
+	return instance;
+}
+
+/**
+ * Set multiple fields at once. Allows you to provide multiple key-value pairs.
+ */
+template <typename... R> static inline
+void setFields(State* state, int index, R&&... args) {
+	static_assert(sizeof...(R) % 2 == 0, "Field parameters must appear in pairs");
+	internal::EntryPusher<R...>::push(state, index, std::forward<R>(args)...);
+}
+
+/**
+ * Create a new table and set its fields.
+ */
+template <typename... R> static inline
+void newTable(State* state, R&&... args) {
+	lua_newtable(state);
+	setFields(state, lua_gettop(state), std::forward<R>(args)...);
+}
+
+LUWRA_NS_END
+
+#endif

+ 0 - 52
lib/luwra/stack.hpp

@@ -153,58 +153,6 @@ R apply(State* state, const std::function<R(A...)>& function_object) {
 	return apply(state, 1, function_object);
 }
 
-/**
- * Check if two values are equal.
- */
-static inline
-bool equal(State* state, int index1, int index2) {
-#if LUA_VERSION_NUM <= 501
-	return lua_equal(state, index1, index2);
-#else
-	return lua_compare(state, index1, index2, LUA_OPEQ);
-#endif
-}
-
-/**
- * Register a value as a global.
- */
-template <typename V> static inline
-void setGlobal(State* state, const std::string& name, V value) {
-	assert(1 == push(state, value));
-	lua_setglobal(state, name.c_str());
-}
-
-/**
- * Retrieve a global value.
- */
-template <typename V> static inline
-V getGlobal(State* state, const std::string& name) {
-	lua_getglobal(state, name.c_str());
-
-	V instance = read<V>(state, -1);
-	lua_pop(state, 1);
-
-	return instance;
-}
-
-/**
- * Set multiple fields at once. Allows you to provide multiple key-value pairs.
- */
-template <typename... R> static inline
-void setFields(State* state, int index, R&&... args) {
-	static_assert(sizeof...(R) % 2 == 0, "Field parameters must appear in pairs");
-	internal::EntryPusher<R...>::push(state, index, std::forward<R>(args)...);
-}
-
-/**
- * Create a new table and set its fields.
- */
-template <typename... R> static inline
-void newTable(State* state, R&&... args) {
-	lua_newtable(state);
-	setFields(state, lua_gettop(state), std::forward<R>(args)...);
-}
-
 LUWRA_NS_END
 
 #endif

+ 1 - 1
lib/luwra/state.hpp

@@ -8,7 +8,7 @@
 #define LUWRA_STATEWRAPPER_H_
 
 #include "common.hpp"
-#include "stack.hpp"
+#include "auxiliary.hpp"
 
 #include <string>
 #include <utility>