From 294e37f8227818d7f6ee3d678f469b17f33e7a9e Mon Sep 17 00:00:00 2001 From: Rapptz Date: Tue, 26 Nov 2013 04:06:48 -0500 Subject: [PATCH] Allow creation of tables --- sol/state.hpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) 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; }