int CLuaFileDefs::fileSetPos ( lua_State* luaVM ) { // int fileSetPos ( file theFile, int offset ) CScriptFile* pFile; long lPosition; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pFile ); argStream.ReadNumber ( lPosition ); if ( !argStream.HasErrors () ) { if ( lPosition >= 0 ) { long lResultPosition = pFile->SetPointer ( static_cast < unsigned long > ( lPosition ) ); if ( lResultPosition != -1 ) { // Set the position and return where we actually got it put lua_pushnumber ( luaVM, lResultPosition ); return 1; } else { m_pScriptDebugging->LogBadPointer ( luaVM, "file", 1 ); } } else m_pScriptDebugging->LogCustom ( luaVM, "Bad file position" ); } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); // Error lua_pushnil ( luaVM ); return 1; }
int CLuaFileDefs::fileClose ( lua_State* luaVM ) { // string fileClose ( file ) // Grab the file pointer CScriptFile* pFile = NULL; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pFile ); if ( !argStream.HasErrors ( ) ) { if ( pFile ) { // Close the file and delete it pFile->Unload (); //m_pElementDeleter->Delete ( pFile ); g_pClientGame->GetElementDeleter()->Delete ( pFile ); // Success. Return true lua_pushboolean ( luaVM, true ); return 1; } else m_pScriptDebugging->LogBadPointer ( luaVM, "file", 1 ); } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); // Error lua_pushnil ( luaVM ); return 1; }
int CLuaFileDefs::fileIsEOF ( lua_State* luaVM ) { // bool fileIsEOF ( file ) // Grab the file pointer CScriptFile* pFile = NULL; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pFile ); if ( !argStream.HasErrors ( ) ) { if ( pFile ) { // Return its EOF state lua_pushboolean ( luaVM, pFile->IsEOF () ); return 1; } else m_pScriptDebugging->LogBadPointer ( luaVM, "file", 1 ); } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); // Error lua_pushnil ( luaVM ); return 1; }
// Called by Lua when file userdatas are garbage collected int CLuaFileDefs::fileCloseGC ( lua_State* luaVM ) { CScriptFile* pFile; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pFile ); if ( !argStream.HasErrors () ) { // Close the file and delete it pFile->Unload (); m_pElementDeleter->Delete ( pFile ); // This file wasn't closed, so we should warn // the scripter that they forgot to close it. m_pScriptDebugging->LogWarning ( luaVM, "Unclosed file (%s) was garbage collected. Check your resource for dereferenced files.", pFile->GetFilePath ().c_str () ); // TODO: The debug info reported when Lua automatically garbage collects will // actually be the exact point Lua pauses for collection. Find a way to // remove the line number & script file completely. lua_pushboolean ( luaVM, true ); return 1; } lua_pushnil ( luaVM ); return 1; }
int CLuaFileDefs::fileGetSize ( lua_State* luaVM ) { // int fileGetSize ( file ) CScriptFile* pFile; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pFile ); if ( !argStream.HasErrors ( ) ) { long lSize = pFile->GetSize (); if ( lSize != -1 ) { // Return its size lua_pushnumber ( luaVM, lSize ); } else { m_pScriptDebugging->LogBadPointer ( luaVM, "file", 1 ); lua_pushnil ( luaVM ); } return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushnil ( luaVM ); return 1; }
int CLuaFileDefs::fileGetPos ( lua_State* luaVM ) { // int fileGetPos ( file ) // Grab the file pointer CScriptFile* pFile = NULL; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pFile ); if ( !argStream.HasErrors ( ) ) { if ( pFile ) { long lPosition = pFile->GetPointer (); if ( lPosition != -1 ) { // Return its position lua_pushnumber ( luaVM, lPosition ); } else { m_pScriptDebugging->LogBadPointer ( luaVM, "file", 1 ); lua_pushnil ( luaVM ); } return 1; } else m_pScriptDebugging->LogBadPointer ( luaVM, "file", 1 ); } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); // Error lua_pushnil ( luaVM ); return 1; }
EXPORT_C CScriptFile* CScriptFile::NewLC(CHTTPTestUtils& aTestUtils, const TDesC& aComponent) { CScriptFile* self = new (ELeave) CScriptFile(aTestUtils); CleanupStack::PushL(self); self->ConstructL(aComponent); return self; }
EXPORT_C TInt CScriptFile::ItemValueL(CHTTPTestUtils& aTestUtils, const TDesC& aComponent, const TDesC& aScript, const TDesC& aSection, const TDesC& aItem, const TInt aDefault) { CScriptFile* self = NewLC(aTestUtils, aComponent, aScript); TInt output = self->ItemValue(aSection, aItem, aDefault); CleanupStack::PopAndDestroy(self); return output; }
int CLuaFileDefs::fileFlush ( lua_State* luaVM ) { // string fileFlush ( file ) // Grab the file pointer CScriptFile* pFile = NULL; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pFile ); if ( !argStream.HasErrors ( ) ) { if ( pFile ) { // Flush the file pFile->Flush (); // Success. Return true lua_pushboolean ( luaVM, true ); return 1; } else m_pScriptDebugging->LogBadPointer ( luaVM, "file", 1 ); } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); // Error lua_pushnil ( luaVM ); return 1; }
void ScriptFile_ReadLine_Generic(asIScriptGeneric *gen) { CScriptFile *file = (CScriptFile*)gen->GetObject(); std::string *str = (std::string*)gen->GetArgAddress(0); int len = file->ReadLine(*str); gen->SetReturnDWord(len); }
int CLuaFileDefs::fileClose ( lua_State* luaVM ) { // bool fileClose ( file theFile ) CScriptFile* pFile; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pFile ); if ( !argStream.HasErrors () ) { // Close the file and delete it pFile->Unload (); m_pElementDeleter->Delete ( pFile ); // Success. Return true lua_pushboolean ( luaVM, true ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); // Error lua_pushnil ( luaVM ); return 1; }
int CLuaFileDefs::fileGetSize ( lua_State* luaVM ) { // int fileGetSize ( file theFile ) CScriptFile* pFile; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pFile ); if ( !argStream.HasErrors () ) { long lSize = pFile->GetSize (); if ( lSize != -1 ) { // Return its size lua_pushnumber ( luaVM, lSize ); return 1; } else argStream.SetCustomError ( "Bad file handle" ); } if ( argStream.HasErrors () ) m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); // Error lua_pushnil ( luaVM ); return 1; }
void ScriptFile_Open_Generic(asIScriptGeneric *gen) { CScriptFile *file = (CScriptFile*)gen->GetObject(); std::string *f = (std::string*)gen->GetArgAddress(0); std::string *m = (std::string*)gen->GetArgAddress(1); int r = file->Open(*f, *m); gen->SetReturnDWord(r); }
int CLuaFileDefs::fileWrite ( lua_State* luaVM ) { // int fileWrite ( file theFile, string string1 [, string string2, string string3 ...]) CScriptFile* pFile; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pFile ); // Ensure we have atleast one string if ( !argStream.NextIsString () ) argStream.SetTypeError ( "string" ); if ( !argStream.HasErrors () ) { long lBytesWritten = 0; // Total bytes written // While we're not out of string arguments // (we will always have at least one string because we validated it above) while ( argStream.NextIsString () ) { // Grab argument and length SString strData; argStream.ReadString ( strData ); unsigned long ulDataLen = strData.length (); // Write the data long lArgBytesWritten = pFile->Write ( ulDataLen, strData ); // Did the file mysteriously disappear? if ( lArgBytesWritten == -1 ) { m_pScriptDebugging->LogBadPointer ( luaVM, "file", 1 ); lua_pushnil ( luaVM ); return 1; } // Add the number of bytes written to our counter lBytesWritten += lArgBytesWritten; } #ifdef MTA_CLIENT // Inform file verifier if ( lBytesWritten != 0 ) g_pClientGame->GetResourceManager ()->OnFileModifedByScript ( pFile->GetAbsPath (), "fileWrite" ); #endif // Return the number of bytes we wrote lua_pushnumber ( luaVM, lBytesWritten ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); // Error lua_pushnil ( luaVM ); return 1; }
EXPORT_C HBufC* CScriptFile::ItemValueLC(CHTTPTestUtils& aTestUtils, const TDesC& aComponent, const TDesC& aScript, const TDesC& aSection, const TDesC& aItem, const TDesC& aDefault) { CScriptFile* self = NewLC(aTestUtils, aComponent, aScript); TPtrC output(self->ItemValue(aSection, aItem, aDefault)); HBufC* buf = output.AllocL(); CleanupStack::PopAndDestroy(self); CleanupStack::PushL(buf); return buf; }
int CLuaFileDefs::fileRead ( lua_State* luaVM ) { // string fileRead ( file, count ) // Grab the file pointer CScriptFile* pFile = NULL; unsigned long ulCount = 0; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pFile ); argStream.ReadNumber ( ulCount ); if ( !argStream.HasErrors ( ) ) { if ( pFile ) { if ( ulCount > 0 ) { // Allocate a buffer to read the stuff into and read some shit into it char* pReadContent = new char [ulCount + 1]; long lBytesRead = pFile->Read ( ulCount, pReadContent ); if ( lBytesRead != -1 ) { // Push the string onto the lua stack. Use pushlstring so we are binary // compatible. Normal push string takes zero terminated strings. lua_pushlstring ( luaVM, pReadContent, lBytesRead ); } else { m_pScriptDebugging->LogBadPointer ( luaVM, "file", 1 ); lua_pushnil ( luaVM ); } // Delete our read content. Lua should've stored it delete[] pReadContent; // We're returning the result string return 1; } else { // Reading zero bytes from a file results in an empty string lua_pushstring ( luaVM, "" ); return 1; } } else m_pScriptDebugging->LogBadPointer ( luaVM, "file", 1 ); } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); // Error lua_pushnil ( luaVM ); return 1; }
CFileTree::CFileTree() : m_pFileList(0), m_nFiles(0) { CScriptFile file; file.SetFile("ExampleScript.txt"); AddFileToList(file); }
int CLuaFileDefs::fileWrite ( lua_State* luaVM ) { // string fileWrite ( file, string [, string2, string3, ...] ) // Grab the file pointer CScriptFile* pFile = NULL; SString strMessage = ""; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pFile ); argStream.ReadString ( strMessage ); if ( !argStream.HasErrors ( ) ) { if ( pFile ) { // While we're not out of string arguments long lBytesWritten = 0; long lArgBytesWritten = 0; do { unsigned long ulDataLen = strMessage.length ( ); // Write it and add the bytes written to our total bytes written lArgBytesWritten = pFile->Write ( ulDataLen, strMessage.c_str ( ) ); if ( lArgBytesWritten == -1 ) { m_pScriptDebugging->LogBadPointer ( luaVM, "file", 1 ); lua_pushnil ( luaVM ); return 1; } lBytesWritten += lArgBytesWritten; if ( !argStream.NextIsString ( ) ) break; argStream.ReadString ( strMessage ); } while ( true ); // Return the number of bytes we wrote lua_pushnumber ( luaVM, lBytesWritten ); return 1; } else m_pScriptDebugging->LogBadPointer ( luaVM, "file", 1 ); } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); // Error lua_pushnil ( luaVM ); return 1; }
void CScriptFile::CopyInDefaultsL(CScriptSection& aSection, const TDesC& aDefaultFile) { CScriptFile* file = CScriptFile::NewLC(iTestUtils, *iComponent, aDefaultFile); TInt count = file->Sections().Count(); if (count > 0) { CScriptSection& def = *file->Sections()[0]; aSection.SetDefaultsL(def); } CleanupStack::PopAndDestroy(file); }
int CLuaFileDefs::fileWrite ( lua_State* luaVM ) { // string fileWrite ( file, string [, string2, string3, ...] ) CScriptFile* pFile; SString strMessage; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pFile ); argStream.ReadString ( strMessage ); if ( !argStream.HasErrors ( ) ) { // While we're not out of string arguments long lBytesWritten = 0; long lArgBytesWritten = 0; do { unsigned long ulDataLen = strMessage.length ( ); // Write it and add the bytes written to our total bytes written lArgBytesWritten = pFile->Write ( ulDataLen, strMessage.c_str ( ) ); if ( lArgBytesWritten == -1 ) { m_pScriptDebugging->LogBadPointer ( luaVM, "file", 1 ); lua_pushnil ( luaVM ); return 1; } lBytesWritten += lArgBytesWritten; if ( !argStream.NextIsString ( ) ) break; argStream.ReadString ( strMessage ); } while ( true ); // Inform file verifier if ( lBytesWritten > 0 ) g_pClientGame->GetResourceManager()->OnFileModifedByScript( pFile->GetAbsPath(), "fileWrite" ); // Return the number of bytes we wrote lua_pushnumber ( luaVM, lBytesWritten ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushnil ( luaVM ); return 1; }
int CLuaFileDefs::fileWrite ( lua_State* luaVM ) { // int fileWrite ( file theFile, string string1 [, string string2, string string3 ...]) CScriptFile* pFile; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pFile ); if ( !argStream.NextIsString () ) argStream.SetTypeError ( "string" ); if ( !argStream.HasErrors () ) { // While we're not out of string arguments long lBytesWritten = 0; long lArgBytesWritten = 0; do { // Grab argument and length SString strData; argStream.ReadString ( strData ); unsigned long ulDataLen = strData.length (); // Write it and add the bytes written to our total bytes written lArgBytesWritten = pFile->Write ( ulDataLen, strData ); if ( lArgBytesWritten == -1 ) { m_pScriptDebugging->LogBadPointer ( luaVM, "file", 1 ); lua_pushnil ( luaVM ); return 1; } lBytesWritten += lArgBytesWritten; } while ( argStream.NextIsString () ); // Return the number of bytes we wrote lua_pushnumber ( luaVM, lBytesWritten ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); // Error lua_pushnil ( luaVM ); return 1; }
int CLuaFileDefs::fileRead ( lua_State* luaVM ) { // string fileRead ( file, count ) CScriptFile* pFile; unsigned long ulCount = 0; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pFile ); argStream.ReadNumber ( ulCount ); if ( !argStream.HasErrors ( ) ) { if ( ulCount > 0 ) { // Allocate a buffer to read the stuff into and read some shit into it CBuffer buffer; long lBytesRead = pFile->Read ( ulCount, buffer ); if ( lBytesRead != -1 ) { // Push the string onto the lua stack. Use pushlstring so we are binary // compatible. Normal push string takes zero terminated strings. lua_pushlstring ( luaVM, buffer.GetData(), lBytesRead ); } else { m_pScriptDebugging->LogBadPointer ( luaVM, "file", 1 ); lua_pushnil ( luaVM ); } // We're returning the result string return 1; } else { // Reading zero bytes from a file results in an empty string lua_pushstring ( luaVM, "" ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushnil ( luaVM ); return 1; }
int CLuaFileDefs::fileIsEOF ( lua_State* luaVM ) { // bool fileIsEOF ( file ) CScriptFile* pFile; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pFile ); if ( !argStream.HasErrors () ) { // Return its EOF state lua_pushboolean ( luaVM, pFile->IsEOF () ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushnil ( luaVM ); return 1; }
int CLuaFileDefs::fileGetPath ( lua_State* luaVM ) { // string fileGetPath ( file theFile ) CScriptFile* pFile; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pFile ); if ( !argStream.HasErrors () ) { // Grab our lua VM CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( pLuaMain ) { CResource* pThisResource = pLuaMain->GetResource (); CResource* pFileResource = pFile->GetResource (); SString strFilePath = pFile->GetFilePath (); // If the calling resource is not the resource the file resides in // we need to prepend :resourceName to the path if ( pThisResource != pFileResource ) { #ifdef MTA_CLIENT strFilePath = SString ( ":%s/%s", pFileResource->GetName (), *strFilePath ); #else strFilePath = SString ( ":%s/%s", *pFileResource->GetName (), *strFilePath ); #endif } lua_pushlstring ( luaVM, strFilePath, strFilePath.length () ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); // Failed lua_pushboolean ( luaVM, false ); return 1; }
void CHttpTestSingleTrans::ConstructL(CScriptFile& aIniFile, CScriptFile* aIniSettingsFile, const TInt aSectionNumber) { CHttpTestTransactions::ConstructL(aIniFile, aIniSettingsFile, aSectionNumber); _LIT(KLogCipherSuite, "LogCipherSuite"); CScriptSectionItem* cipherSuiteItem = aIniFile.Section(aSectionNumber).Item(KLogCipherSuite); _LIT(KItemSet, "1"); if(cipherSuiteItem && cipherSuiteItem->Value().Compare(KItemSet) == 0) { iLogCipherSuite = ETrue; } }
int CLuaFileDefs::fileGetPath( lua_State* luaVM ) { // string fileGetPath ( file theFile ) CScriptFile* pFile; CScriptArgReader argStream( luaVM ); argStream.ReadUserData( pFile ); if ( !argStream.HasErrors( ) ) { // Grab our lua VM CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine( luaVM ); if ( pLuaMain ) { // We have a resource argument? CResource* pThisResource = pLuaMain->GetResource( ); CResource* pFileResource = pFile->GetResource( ); const SString& strFilePath = pFile->GetFilePath( ); SString outPath = strFilePath; // If the calling resource is not the resource the file resides in // we need to prepend :resourceName to the path if ( pThisResource != pFileResource ) { outPath = ":" + pFileResource->GetName() + "/" + outPath; } lua_pushlstring( luaVM, outPath.c_str( ), outPath.length( ) ); return 1; } } else m_pScriptDebugging->LogCustom( luaVM, argStream.GetFullErrorMessage( ) ); // Failed lua_pushboolean( luaVM, false ); return 1; }
int CLuaFileDefs::fileSetPos ( lua_State* luaVM ) { // bool fileSetPos ( file ) // Grab the file pointer CScriptFile* pFile = NULL; unsigned long ulPosition = 0; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pFile ); argStream.ReadNumber ( ulPosition ); if ( !argStream.HasErrors ( ) ) { if ( pFile ) { long lResultPosition = pFile->SetPointer ( ulPosition ); if ( lResultPosition != -1 ) { // Set the position and return where we actually got it put lua_pushnumber ( luaVM, lResultPosition ); } else { m_pScriptDebugging->LogBadPointer ( luaVM, "file", 1 ); lua_pushnil ( luaVM ); } return 1; } else m_pScriptDebugging->LogBadPointer ( luaVM, "file", 1 ); } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); // Error lua_pushnil ( luaVM ); return 1; }
int CLuaFileDefs::fileFlush ( lua_State* luaVM ) { // bool fileFlush ( file theFile ) CScriptFile* pFile; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pFile ); if ( !argStream.HasErrors () ) { // Flush the file pFile->Flush (); // Success. Return true lua_pushboolean ( luaVM, true ); return 1; } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); // Error lua_pushnil ( luaVM ); return 1; }
int CLuaFileDefs::fileCreate ( lua_State* luaVM ) { // file fileCreate ( string filePath ) SString filePath; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( filePath ); if ( !argStream.HasErrors () ) { // Grab our lua VM CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( !g_pNet->ValidateBinaryFileName ( filePath ) ) { argStream.SetCustomError ( SString ( "Filename not allowed %s", *filePath ), "File error" ); } else if ( pLuaMain ) { SString strAbsPath; SString strMetaPath; CResource* pThisResource = pLuaMain->GetResource (); CResource* pResource = pThisResource; if ( CResourceManager::ParseResourcePathInput ( filePath, pResource, strAbsPath, strMetaPath ) ) { // Inform file verifier g_pClientGame->GetResourceManager()->FileModifedByScript( strAbsPath ); // Make sure the destination folder exist so we can create the file MakeSureDirExists ( strAbsPath.c_str () ); // Create the file to create eAccessType accessType = filePath[0] == '@' ? eAccessType::ACCESS_PRIVATE : eAccessType::ACCESS_PUBLIC; CScriptFile* pFile = new CScriptFile( pThisResource->GetScriptID( ), strMetaPath.c_str(), DEFAULT_MAX_FILESIZE, accessType); assert ( pFile ); // Try to load it if ( pFile->Load ( pResource, CScriptFile::MODE_CREATE ) ) { // Make it a child of the resource's file root pFile->SetParent ( pResource->GetResourceDynamicEntity () ); // Add it to the scrpt resource element group CElementGroup* pGroup = pThisResource->GetElementGroup (); if ( pGroup ) { pGroup->Add ( pFile ); } // Success. Return the file. lua_pushelement ( luaVM, pFile ); return 1; } else { // Delete the file again delete pFile; // Output error argStream.SetCustomError ( SString ( "Unable to create %s", *filePath ), "File error" ); } } } } if ( argStream.HasErrors () ) m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); // Failed lua_pushboolean ( luaVM, false ); return 1; }
int CLuaFileDefs::fileOpen ( lua_State* luaVM ) { // file fileOpen ( string filePath [, bool readOnly = false ] ) SString filePath; bool readOnly; CScriptArgReader argStream ( luaVM ); argStream.ReadString ( filePath ); argStream.ReadBool ( readOnly, false ); if ( !argStream.HasErrors () ) { // Grab our lua VM CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); if ( pLuaMain ) { SString strAbsPath; SString strMetaPath; CResource* pThisResource = pLuaMain->GetResource (); CResource* pResource = pThisResource; if ( CResourceManager::ParseResourcePathInput ( filePath, pResource, strAbsPath, strMetaPath ) ) { // Inform file verifier if ( !readOnly ) g_pClientGame->GetResourceManager()->FileModifedByScript( strAbsPath ); // Create the file to create eAccessType accessType = filePath[0] == '@' ? eAccessType::ACCESS_PRIVATE : eAccessType::ACCESS_PUBLIC; CScriptFile* pFile = new CScriptFile( pThisResource->GetScriptID( ), strMetaPath.c_str( ), DEFAULT_MAX_FILESIZE, accessType ); assert ( pFile ); // Try to load it if ( pFile->Load ( pResource, readOnly ? CScriptFile::MODE_READ : CScriptFile::MODE_READWRITE ) ) { // Make it a child of the resource's file root pFile->SetParent ( pResource->GetResourceDynamicEntity () ); // Grab its owner resource CResource* pParentResource = pLuaMain->GetResource (); if ( pParentResource ) { // Add it to the scrpt resource element group CElementGroup* pGroup = pParentResource->GetElementGroup (); if ( pGroup ) { pGroup->Add ( pFile ); } } // Success. Return the file. lua_pushelement ( luaVM, pFile ); return 1; } else { // Delete the file again delete pFile; // Output error argStream.SetCustomError( SString( "unable to load file '%s'", *filePath ) ); } } } } if ( argStream.HasErrors () ) m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); // Failed lua_pushboolean ( luaVM, false ); return 1; }