changeset 226:24501d428db3

Luae: clean up and add comments
author David Demelier <markand@malikania.fr>
date Fri, 09 May 2014 17:44:36 +0200
parents e01ee0c72c43
children 4c9b2a3f2396
files C++/Luae.cpp C++/Luae.h
diffstat 2 files changed, 68 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/C++/Luae.cpp	Fri May 09 17:12:25 2014 +0200
+++ b/C++/Luae.cpp	Fri May 09 17:44:36 2014 +0200
@@ -16,8 +16,6 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#include <sstream>
-
 #include "Luae.h"
 
 void Luae::doexecute(lua_State *L, int status)
--- a/C++/Luae.h	Fri May 09 17:12:25 2014 +0200
+++ b/C++/Luae.h	Fri May 09 17:44:36 2014 +0200
@@ -24,15 +24,11 @@
  * @brief Lua C++ extended API
  */
 
-#include <cassert>
-#include <cstddef>
-#include <functional>
 #include <memory>
 #include <stdexcept>
 #include <string>
 #include <type_traits>
 #include <unordered_map>
-#include <vector>
 
 #include <lua.hpp>
 
@@ -195,7 +191,9 @@
 	};
 	
 	template <typename T>
-	struct IsSharedUserdata : std::false_type {};
+	struct IsSharedUserdata : std::false_type 
+	{
+	};
 
 	template <typename T>
 	struct IsSharedUserdata<std::shared_ptr<T>> {
@@ -925,6 +923,13 @@
 	 */
 	static void require(lua_State *L, const std::string &name, lua_CFunction func);
 
+	/**
+	 * Push a custom type to Lua.
+	 *
+	 * @param L the Lua state
+	 * @param value the value
+	 * @return 1
+	 */
 	template <typename T>
 	static int push(lua_State *L,
 			 const T &value,
@@ -937,6 +942,13 @@
 		return 1;
 	}
 
+	/**
+	 * Push a userdata to Lua.
+	 *
+	 * @param L the Lua state
+	 * @param value the value
+	 * @return 1
+	 */
 	template <typename T>
 	static int push(lua_State *L,
 			 const T &value,
@@ -947,6 +959,12 @@
 		return 1;
 	}
 
+	/**
+	 * Push a userdata as a shared pointer.
+	 *
+	 * @param L the Lua state
+	 * @param value the value
+	 */
 	template <typename T>
 	static int push(lua_State *L,
 			const std::shared_ptr<T> &value,
@@ -997,6 +1015,13 @@
 		push<const char *>(L, s);
 	}
 
+	/**
+	 * Get a custom type without check.
+	 *
+	 * @param L the Lua state
+	 * @param index the index
+	 * @return the type value
+	 */
 	template <typename T>
 	static EnableIf<IsCustom<T>::value, T>
 	get(lua_State *L, int index)
@@ -1006,6 +1031,13 @@
 		return TypeInfo<T>::get(L, index);
 	}
 
+	/**
+	 * Get a userdata without check. Absolute insecure.
+	 *
+	 * @param L the Lua state
+	 * @param index the index
+	 * @return T *
+	 */
 	template <typename T>
 	static EnableIf<IsUserdata<T>::value, T *>
 	get(lua_State *L, int index)
@@ -1013,13 +1045,27 @@
 		return Luae::toType<T *>(L, index);
 	}
 	
+	/**
+	 * Get a userdata from a shared pointer without check.
+	 *
+	 * @param L the Lua state
+	 * @param index the index
+	 * @return the std::shared_ptr
+	 */
 	template <typename T>
-	static EnableIf<IsSharedUserdata<std::shared_ptr<T>>::value, std::shared_ptr<T>>
+	static EnableIf<IsSharedUserdata<T>::value, T>
 	get(lua_State *L, int index)
 	{
-		return *Luae::toType<std::shared_ptr<T> *>(L, index);
+		return *Luae::toType<T *>(L, index);
 	}
-	
+
+	/**
+	 * Get a custom type with check.
+	 *
+	 * @param L the Lua state
+	 * @param index the index
+	 * @return the type
+	 */
 	template <typename T>
 	static EnableIf<IsCustom<T>::value, T>
 	check(lua_State *L, int index)
@@ -1029,6 +1075,13 @@
 		return TypeInfo<T>::check(L, index);
 	}
 
+	/**
+	 * Get a userdata with checks
+	 *
+	 * @param L the Lua state
+	 * @param index the index
+	 * @return T *
+	 */
 	template <typename T>
 	static EnableIf<IsUserdata<T>::value, T *>
 	check(lua_State *L, int index)
@@ -1036,6 +1089,13 @@
 		return Luae::toType<T *>(L, index, TypeInfo<T>::name);
 	}
 
+	/**
+	 * Get a userdata from a shared pointer with checks.
+	 *
+	 * @param L the Lua state
+	 * @param index the index
+	 * @return the std::shared_ptr
+	 */
 	template <typename T>
 	static EnableIf<IsSharedUserdata<T>::value, T>
 	check(lua_State *L, int index)