IScriptObject* CScriptSystem::GetGlobalObject() { CScriptObject* pObj = CreateScriptObject(); lua_pushvalue(m_pLS, LUA_GLOBALSINDEX); pObj->CreateEmpty(); pObj->Attach(); return pObj; }
void CDescription::WriteToConfig( void ) { CScriptObject *pObj; pObj = pObjList; while ( pObj ) { pObj->WriteToConfig(); pObj = pObj->pNext; } }
IScriptObject* CScriptSystem::CreateGlobalObject(const char* sName) { SCRIPT_STACK_CHECK(m_pLS); CScriptObject* pObj = CreateScriptObject(); if (!pObj->CreateGlobal(sName)) { pObj->Release(); return NULL; }; return pObj; }
IScriptObject* CScriptSystem::CreateObject() { SCRIPT_STACK_CHECK(m_pLS); CScriptObject* pObj = CreateScriptObject(); if (!pObj->Create()) { pObj->Release(); return NULL; }; return pObj; }
void CDescription::WriteToFile( FileHandle_t fp ) { CScriptObject *pObj; WriteFileHeader( fp ); pObj = pObjList; while ( pObj ) { pObj->WriteToFile( fp ); pObj = pObj->pNext; } }
void CDescription::WriteToScriptFile( FileHandle_t fp ) { CScriptObject *pObj; WriteScriptHeader( fp ); pObj = pObjList; while ( pObj ) { pObj->WriteToScriptFile( fp ); pObj = pObj->pNext; } g_pFullFileSystem->FPrintf( fp, "}\r\n" ); }
//----------------------------------------------------------------------------- // Purpose: applies all the values in the page //----------------------------------------------------------------------------- void CCreateMultiplayerGameGameplayPage::GatherCurrentValues() { if ( !m_pDescription ) return; // OK CheckButton *pBox; TextEntry *pEdit; ComboBox *pCombo; mpcontrol_t *pList; CScriptObject *pObj; CScriptListItem *pItem; char szValue[256]; char strValue[ 256 ]; pList = m_pList; while ( pList ) { pObj = pList->pScrObj; if ( !pList->pControl ) { pObj->SetCurValue( pObj->defValue ); pList = pList->next; continue; } switch ( pObj->type ) { case O_BOOL: pBox = (CheckButton *)pList->pControl; sprintf( szValue, "%s", pBox->IsSelected() ? "1" : "0" ); break; case O_NUMBER: pEdit = ( TextEntry * )pList->pControl; pEdit->GetText( strValue, sizeof( strValue ) ); sprintf( szValue, "%s", strValue ); break; case O_STRING: pEdit = ( TextEntry * )pList->pControl; pEdit->GetText( strValue, sizeof( strValue ) ); sprintf( szValue, "%s", strValue ); break; case O_LIST: pCombo = ( ComboBox *)pList->pControl; pCombo->GetText( strValue, sizeof( strValue ) ); pItem = pObj->pListItems; int n = (int)pObj->fdefValue; while ( pItem ) { if ( !stricmp( pItem->szItemText, strValue ) ) { break; } pItem = pItem->pNext; } if ( pItem ) { sprintf( szValue, "%s", pItem->szValue ); } else //Couln't find index { sprintf( szValue, "%s", pObj->defValue ); } break; } // Remove double quotes and % characters UTIL_StripInvalidCharacters( szValue ); strcpy( strValue, szValue ); pObj->SetCurValue( strValue ); pList = pList->next; } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CTFOptionsAdvancedPanel::GatherCurrentValues() { if (!m_pDescription) return; // OK CTFAdvCheckButton *pBox; TextEntry *pEdit; ComboBox *pCombo; CTFAdvSlider *pScroll; mpcontrol_t *pList; CScriptObject *pObj; CScriptListItem *pItem; char szValue[256]; char strValue[256]; int iValue; pList = m_pList; while (pList) { pObj = pList->pScrObj; if (!pList->pControl) { pObj->SetCurValue(pObj->defValue); pList = pList->next; continue; } switch (pObj->type) { case O_BOOL: pBox = (CTFAdvCheckButton *)pList->pControl; sprintf(szValue, "%s", pBox->IsSelected() ? "1" : "0"); break; case O_NUMBER: pEdit = (TextEntry *)pList->pControl; pEdit->GetText(strValue, sizeof(strValue)); sprintf(szValue, "%s", strValue); break; case O_SLIDER: pScroll = (CTFAdvSlider *)pList->pControl; iValue = pScroll->GetValue(); sprintf(szValue, "%i", iValue); break; case O_STRING: pEdit = (TextEntry *)pList->pControl; pEdit->GetText(strValue, sizeof(strValue)); sprintf(szValue, "%s", strValue); break; case O_CATEGORY: break; case O_LIST: pCombo = (ComboBox *)pList->pControl; pCombo->GetText( strValue, sizeof( strValue ) ); int activeItem = pCombo->GetActiveItem(); pItem = pObj->pListItems; // int n = (int)pObj->fdefValue; while (pItem) { if (!activeItem--) break; pItem = pItem->pNext; } if (pItem) { sprintf(szValue, "%s", pItem->szValue); } else // Couln't find index { //assert(!("Couldn't find string in list, using default value")); sprintf(szValue, "%s", pObj->defValue); } break; } // Remove double quotes and % characters UTIL_StripInvalidCharacters(szValue, sizeof(szValue)); strcpy(strValue, szValue); pObj->SetCurValue(strValue); pList = pList->next; } }
bool CDescription::ReadFromBuffer( const char **pBuffer ) { // Get the first token. *pBuffer = engine->ParseFile( *pBuffer, token, sizeof( token ) ); if ( strlen( token ) <= 0 ) return false; // Read VERSION # if ( stricmp ( token, "VERSION" ) ) { Msg( "Expecting 'VERSION', got '%s'", token ); return false; } // Parse in the version # // Get the first token. *pBuffer = engine->ParseFile( *pBuffer, token, sizeof( token ) ); if ( strlen( token ) <= 0 ) { Msg( "Expecting version #" ); return false; } float fVer; fVer = (float)atof( token ); if ( fVer != SCRIPT_VERSION ) { Msg( "Version mismatch, expecting %f, got %f", SCRIPT_VERSION, fVer ); return false; } // Get the "DESCRIPTION" *pBuffer = engine->ParseFile( *pBuffer, token, sizeof( token ) ); if ( strlen( token ) <= 0 ) return false; // Read DESCRIPTION if ( stricmp ( token, "DESCRIPTION" ) ) { Msg( "Expecting 'DESCRIPTION', got '%s'", token ); return false; } // Parse in the description type *pBuffer = engine->ParseFile( *pBuffer, token, sizeof( token ) ); if ( strlen( token ) <= 0 ) { Msg( "Expecting '%s'", m_pszDescriptionType ); return false; } if ( stricmp ( token, m_pszDescriptionType ) ) { Msg( "Expecting %s, got %s", m_pszDescriptionType, token ); return false; } // Parse the { *pBuffer = engine->ParseFile( *pBuffer, token, sizeof( token ) ); if ( strlen( token ) <= 0 ) return false; if ( strcmp( token, "{" ) ) { Msg( "Expecting '{', got '%s'", token ); return false; } const char *pStart; CScriptObject *pObj; // Now read in the objects and link them in while ( 1 ) { pStart = *pBuffer; // Get the first token. *pBuffer = engine->ParseFile( *pBuffer, token, sizeof( token ) ); if ( strlen( token ) <= 0 ) return false; // Read "cvar name" or } when done if ( !stricmp ( token, "}" ) ) break; // Unget the token *pBuffer = pStart; // Create a new object bool mustAdd = true; pObj = FindObject( token ); if ( pObj ) { pObj->ReadFromBuffer( &pStart, false ); mustAdd = false; // already in list } else { pObj = new CScriptObject(); if ( !pObj ) { Msg( "Couldn't create script object" ); return false; } if ( !pObj->ReadFromBuffer( &pStart, true ) ) { delete pObj; return false; } } *pBuffer = pStart; // Add to list // Fixme, move to end of list first if ( mustAdd ) { AddObject( pObj ); } } return true; }