int CLuaFunctionDefs::GetResourceConfig ( lua_State* luaVM ) { CScriptArgReader argStream ( luaVM ); if ( argStream.NextIsUserData ( ) ) m_pScriptDebugging->LogCustom ( luaVM, "getResourceConfig may be using an outdated syntax. Please check and update." ); // Resource and config name CResource* pResource = NULL; SString strInput; SString strAbsPath; SString strMetaPath; argStream.ReadString ( strInput ); if ( !argStream.HasErrors () ) { // Grab our lua main CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( pLuaMain ) { // Grab resource and the config name from arg pResource = pLuaMain->GetResource (); // We have both a resource file to grab the config from and a config name? if ( pResource ) { if ( CResourceManager::ParseResourcePathInput ( strInput, pResource, strAbsPath, strMetaPath ) ) { // Loop through the configs in that resource list < CResourceConfigItem* >::iterator iter = pResource->ConfigIterBegin (); for ( ; iter != pResource->ConfigIterEnd (); iter++ ) { // Matching name? if ( strcmp ( (*iter)->GetShortName(), strMetaPath.c_str() ) == 0 ) { // Return it CResourceConfigItem* pConfig = (CResourceConfigItem*) (*iter); CXMLNode* pNode = pConfig->GetRoot (); if ( pNode ) { lua_pushxmlnode ( luaVM, pNode ); return 1; } } } } } } else m_pScriptDebugging->LogBadType ( luaVM ); } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); // Failed lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFunctionDefs::GetResourceConfig ( lua_State* luaVM ) { if ( lua_istype ( luaVM, 1, LUA_TLIGHTUSERDATA ) ) m_pScriptDebugging->LogCustom ( luaVM, "getResourceConfig may be using an outdated syntax. Please check and update." ); // Resource and config name CResource* pResource = NULL; const char* szInput = NULL; std::string strAbsPath; std::string strMetaPath; if ( lua_istype ( luaVM, 1, LUA_TSTRING ) ) { // Grab our lua main CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( pLuaMain ) { // Grab resource and the config name from arg pResource = pLuaMain->GetResource (); szInput = lua_tostring ( luaVM, 1 ); } } // We have both a resource file to grab the config from and a config name? if ( pResource && szInput ) { if ( CResourceManager::ParseResourcePathInput ( szInput, pResource, strAbsPath, strMetaPath ) ) { // Loop through the configs in that resource list < CResourceConfigItem* >::iterator iter = pResource->ConfigIterBegin (); for ( ; iter != pResource->ConfigIterEnd (); iter++ ) { // Matching name? if ( strcmp ( (*iter)->GetShortName(), strMetaPath.c_str() ) == 0 ) { // Return it CResourceConfigItem* pConfig = (CResourceConfigItem*) (*iter); CXMLNode* pNode = pConfig->GetRoot (); if ( pNode ) { lua_pushxmlnode ( luaVM, pNode ); return 1; } } } } } else m_pScriptDebugging->LogBadType ( luaVM, "getResourceConfig" ); // Failed lua_pushboolean ( luaVM, false ); return 1; }