lua_newtable(L); /* table */ lua_pushnil(L); /* table, nil */ while (lua_next(L, LUA_GLOBALSINDEX) != 0) { /* table, key, value */ switch (lua_type(L, -1)) { case LUA_TNUMBER: case LUA_TBOOLEAN: case LUA_TSTRING: lua_pushvalue(L, -2); /* copy key */ /* table, key, value, key */ lua_insert(L, -3); /* key << 3 */ /* table, key, key, value */ lua_settable(L, -4); /* table[key] = value */ /* table, key */ break; default: lua_pop(L,1); /* table, key */ continue; } } /* table */