bool ScriptState::copy(ScriptState const& from, int n){ if(lua_checkstack(_L, n + 1) != 1) // n objects + cache table return false; bool ret = true; int top1 = from.top(), top2 = top(); lua_newtable(_L); for(int i = 0;i < n; ++i){ if(!inter_copy_one(from, _L, top2+1, top1+i)){ ret = false; break; } } if(ret){ lua_remove(_L, top2+1); // remove cache table }else{ lua_settop(_L, top2); // pop everything on errors } return ret; }