Pārlūkot izejas kodu

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

Ole 10 gadi atpakaļ
vecāks
revīzija
739bcef171
1 mainītis faili ar 9 papildinājumiem un 0 dzēšanām
  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)...);
 }
 
+/**
+ * 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
 
 #endif