diff C++/Luae.h @ 202:99d0887395cc

Luae: Add set() function for LuaeTable
author David Demelier <markand@malikania.fr>
date Sat, 04 Jan 2014 18:02:06 +0100
parents 8ee4a34e166c
children b54c83ed71ca
line wrap: on
line diff
--- a/C++/Luae.h	Sat Jan 04 16:59:09 2014 +0100
+++ b/C++/Luae.h	Sat Jan 04 18:02:06 2014 +0100
@@ -20,6 +20,7 @@
 #define _LUA_H_
 
 #include <cassert>
+#include <cstddef>
 #include <functional>
 #include <memory>
 #include <string>
@@ -169,6 +170,32 @@
 	static T get(lua_State *L, int idx, const std::string &name);
 
 	/**
+	 * Set a table field. Specialized for the same fields as get.
+	 *
+	 * @param L the Lua state
+	 * @param idx the index
+	 * @param name the field name
+	 * @param value the value
+	 * @see get
+	 */
+	template <typename T>
+	static void set(lua_State *L, int idx, const std::string &name, const T &value);
+
+	/**
+	 * Overload for string literals.
+	 *
+	 * @param L the Lua state
+	 * @param idx the index
+	 * @param name the field name
+	 * @param s the string
+	 */
+	template <size_t N>
+	static void set(lua_State *L, int idx, const std::string &name, const char (&s)[N])
+	{
+		set<const char *>(L, idx, name, s);
+	}
+
+	/**
 	 * Require a field from a table.
 	 *
 	 * @param L the Lua state