vector<pair<unsigned, unsigned>> lens;
unsigned len = lua_rawlen(lua_, -1);
unsigned i = 0;
// implement dfs traversal
while (true) {
while (i < len) {
DVLOG(1) << "Stack " << lua_gettop(lua_) << "/" << i << "/" << len;
int t = lua_rawgeti(lua_, -1, i + 1); // push table element
if (t == LUA_TTABLE) {
if (lens.size() >= 127) // reached depth 127
return false;
lens.emplace_back(i + 1, len); // save the parent state.
// reset to iterate on the next table.
i = 0;
len = lua_rawlen(lua_, -1);
} else {
lua_pop(lua_, 1); // pop table element
++i;
}
}
if (lens.empty()) // exit criteria
break;
// unwind to the state before we went down the stack.
tie(i, len) = lens.back();
lens.pop_back();
lua_pop(lua_, 1);
};
return true;