Explorar o código

Make Table constructors be able to create tables for you

Ole %!s(int64=9) %!d(string=hai) anos
pai
achega
3b834d734b
Modificáronse 1 ficheiros con 8 adicións e 0 borrados
  1. 8 0
      lib/luwra/tables.hpp

+ 8 - 0
lib/luwra/tables.hpp

@@ -133,6 +133,14 @@ struct Table {
 		luaL_checktype(state, index, LUA_TTABLE);
 	}
 
+	Table(State* state):
+		Table(state, (lua_newtable(state), -1))
+	{}
+
+	Table(State* state, const MemberMap& fields):
+		Table(state, (luwra::push(state, fields), -1))
+	{}
+
 	template <typename K> inline
 	internal::TableAccessor<internal::Path<const Reference&, K>> access(K&& key) const {
 		return {ref.impl->state, {ref, std::forward<K>(key)}};