浏览代码

Add 'new_table' helper which allows you to create new table easily

Ole 10 年之前
父节点
当前提交
739bcef171
共有 1 个文件被更改,包括 9 次插入0 次删除
  1. 9 0
      lib/luwra/stack.hpp

+ 9 - 0
lib/luwra/stack.hpp

@@ -151,6 +151,15 @@ void set_fields(State* state, int index, R&&... args) {
 	internal::EntryPusher<R...>::push(state, index, std::forward<R>(args)...);
 	internal::EntryPusher<R...>::push(state, index, std::forward<R>(args)...);
 }
 }
 
 
+/**
+ * Create a new table and set its fields.
+ */
+template <typename... R> static inline
+void new_table(State* state, R&&... args) {
+	lua_newtable(state);
+	set_fields(state, lua_gettop(state), std::forward<R>(args)...);
+}
+
 LUWRA_NS_END
 LUWRA_NS_END
 
 
 #endif
 #endif