/** \brief add Widgets to a Container * \details This accepts multiple Widgets. * */ int UI_Lua::add(lua_State *L){ int n = lua_gettop(L); // Number of arguments if (n >= 2){ Container* outer = (Container*)checkWidget(L,1); luaL_argcheck(L, outer->GetMask() & WIDGET_CONTAINER, 1, "`Container' expected."); for(int i=2; i<=n; i++){ Widget* inner = checkWidget(L,i); outer->AddChild( inner ); } } else { luaL_error(L, "Got %d arguments expected 2 or more (self, widget [...])", n); } return 0; }
Container* Interpreter::Pop( bool setParent ) { ContainerPtr child = m_ContainerStack.Get().top(); m_ContainerStack.Get().pop(); if ( setParent ) { if ( m_ContainerStack.Get().empty() ) { m_Container->AddChild(child); } else { Container* parent = m_ContainerStack.Get().top(); parent->AddChild(child); } } return child; }
// ReadObject //------------------------------------------------------------------------------ bool TextReader::ReadObject() { // Type AStackString<> type; if ( !GetToken( type ) ) { Error( "Missing type token" ); return false; } // ID AStackString<> id; if ( !GetToken( id ) ) { Error( "Missing id token" ); return false; } // Name AStackString<> name; if ( !GetToken( name ) ) { Error( "Missing name" ); return false; } // Create Object RefObject * refObj = ReflectionInfo::CreateObject( type ); Object * obj = DynamicCast< Object >( refObj ); ASSERT( obj ); // TODO: handle this gracefully (skip) if ( obj == nullptr ) { Error( "Failed to create object" ); return false; } m_ObjectsToInit.Append( obj ); // set name name.Replace( "\"", "" ); // strip quotes obj->SetName( name ); // add to parent if not root if ( m_DeserializationStack.IsEmpty() == false ) { // get parent container RefObject * topRefObject = (RefObject *)( m_DeserializationStack.Top().m_Base ); Container * parentContainer = DynamicCast< Container >( topRefObject ); ASSERT( parentContainer ); // parent is not a container - impossible! // sanity check child Object * child = DynamicCast< Object >( obj ); ASSERT( child ); // child is not an Object - impossible! // add to parent parentContainer->AddChild( child ); } // Push onto stack StackFrame sf; sf.m_Base = obj; sf.m_Reflection = obj->GetReflectionInfoV(); sf.m_ArrayProperty = nullptr; #ifdef DEBUG sf.m_RefObject = obj; sf.m_Struct = nullptr; #endif m_DeserializationStack.Append( sf ); if ( m_RootObject == nullptr ) { m_RootObject = obj; } return true; }