Allow creation of tables

This commit is contained in:
Rapptz 2013-11-26 04:06:48 -05:00
parent 12aac41b9e
commit 294e37f822

View File

@ -145,6 +145,34 @@ public:
return *this;
}
template<typename T>
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<T>(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;
}