diff --git a/sol/state.hpp b/sol/state.hpp index 35f44964..985b5c19 100644 --- a/sol/state.hpp +++ b/sol/state.hpp @@ -145,6 +145,34 @@ public: return *this; } + template + table create_table(T&& key, int narr = 0, int nrec = 0) { + if(narr == 0 && nrec == 0) { + lua_newtable(L.get()); + } + else { + lua_createtable(L.get(), narr, nrec); + } + + table result(L.get()); + lua_pop(L.get(), 1); + global.set(std::forward(key), result); + return result; + } + + table create_table(int narr = 0, int nrec = 0) { + if(narr == 0 && nrec == 0) { + lua_newtable(L.get()); + } + else { + lua_createtable(L.get(), narr, nrec); + } + + table result(L.get()); + lua_pop(L.get(), 1); + return result; + } + table global_table() const { return global; }