Files
itgmania212121/Themes/_fallback/Scripts/04 FileUtils.lua
T

32 lines
828 B
Lua
Raw Normal View History

2011-03-17 01:47:30 -04:00
-- fileutils: quick and dirty, not user prefs oriented file io
File = {
Write = function(path,buf)
local f = RageFileUtil.CreateRageFile()
if f:Open(path, 2) then
f:Write( tostring(buf) )
f:destroy()
return true
else
Trace( "[FileUtils] Error writing to ".. path ..": ".. f:GetError() )
f:ClearError()
f:destroy()
return false
end
end,
Read = function(path)
local f = RageFileUtil.CreateRageFile()
local ret = ""
if f:Open(path, 1) then
ret = tostring( f:Read() )
f:destroy()
return ret
else
Trace( "[FileUtils] Error reading from ".. path ..": ".. f:GetError() )
f:ClearError()
f:destroy()
return nil
end
end
}
-- this code if public domain and/or has no copyright, depending on your
2010-01-26 21:00:30 -06:00
-- country's laws. I wish for you to use this code freely, without restriction.