void RenderState::cloneInto(RenderState* renderState, NodeCloneContext& context) const { GP_ASSERT(renderState); for (std::map<std::string, AutoBinding>::const_iterator it = _autoBindings.begin(); it != _autoBindings.end(); ++it) { renderState->setParameterAutoBinding(it->first.c_str(), it->second); } for (std::vector<MaterialParameter*>::const_iterator it = _parameters.begin(); it != _parameters.end(); ++it) { const MaterialParameter* param = *it; GP_ASSERT(param); MaterialParameter* paramCopy = new MaterialParameter(param->getName()); param->cloneInto(paramCopy); renderState->_parameters.push_back(paramCopy); } renderState->_parent = _parent; if (Node* node = context.findClonedNode(_nodeBinding)) { renderState->setNodeBinding(node); } if (_state) { renderState->setStateBlock(_state); } }
int lua_NodeCloneContext_findClonedNode(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 2: { if ((lua_type(state, 1) == LUA_TUSERDATA) && (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL)) { // Get parameter 1 off the stack. bool param1Valid; gameplay::ScriptUtil::LuaArray<Node> param1 = gameplay::ScriptUtil::getObjectPointer<Node>(2, "Node", false, ¶m1Valid); if (!param1Valid) { lua_pushstring(state, "Failed to convert parameter 1 to type 'Node'."); lua_error(state); } NodeCloneContext* instance = getInstance(state); void* returnPtr = (void*)instance->findClonedNode(param1); if (returnPtr) { gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject)); object->instance = returnPtr; object->owns = false; luaL_getmetatable(state, "Node"); lua_setmetatable(state, -2); } else { lua_pushnil(state); } return 1; } lua_pushstring(state, "lua_NodeCloneContext_findClonedNode - Failed to match the given parameters to a valid function signature."); lua_error(state); break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 2)."); lua_error(state); break; } } return 0; }