Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Persistance API written by PaymentOption for lieudusty.
- function NewVariable( sPath, value )
- if type( value ) == "table" then
- fs.delete( sPath )
- local fFile = fs.open( sPath, "w" )
- for index,valueInTable in pairs( value ) do
- fFile.writeLine( valueInTable )
- end
- fFile.close()
- return
- end
- fs.delete( sPath )
- local fFile = fs.open( sPath, "w" )
- fFile.write( value )
- fFile.close()
- end
- function AppendVarFile( sPath, value )
- if fs.exists( sPath ) then
- if type( value ) == "table" then
- local fFile = fs.open( sPath, "r" )
- local sFileContents = fFile.readAll()
- fFile.close()
- local sTableInString = ""
- for index,val in pairs( value ) do
- sTableInString = sTableInString .. val .. '\n'
- end
- fs.delete( sPath )
- fFile = fs.open( sPath, "w" )
- local sAppendedFile = sFileContents .. '\n' .. sTableInString
- fFile.write( sAppendedFile )
- fFile.close()
- return
- end
- local fFile = fs.open( sPath, "r" )
- local sFileContents = fFile.readAll()
- fFile.close()
- fs.delete( sPath )
- local sAppendedFile = sFileContents .. '\n' .. value
- fFile = fs.open( sPath, "w" )
- fFile.write( sAppendedFile )
- fFile.close()
- end
- end
- function GetVariable( sPath )
- if fs.exists( sPath ) then
- local function GetFileLength_InLines( sPath )
- local fFile = io.open( sPath, "r" )
- local nLength = 0
- for line in fFile:lines() do
- nLength = nLength+1
- end
- fFile:close()
- return nLength
- end
- local nLines = GetFileLength_InLines( sPath )
- local fFile = fs.open( sPath, "r" )
- local tVars = {}
- for nLine=1, nLines do
- table.insert( tVars, fFile.readLine() )
- end
- fFile.close()
- if #tVars == 1 then
- return tVars[1]
- else
- return tVars
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement