Helloworld.lua: fix file_put_contents depending on a wrong return value of io.write + use a cleaner version of if(file == nil) (thanks to Christophe Gragnic)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21731 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
90e3b727dd
commit
408213f263
1 changed files with 3 additions and 3 deletions
|
@ -65,7 +65,7 @@ end
|
||||||
-- Helper function which reads the contents of a file
|
-- Helper function which reads the contents of a file
|
||||||
function file_get_contents(filename)
|
function file_get_contents(filename)
|
||||||
local file = io.open(filename, "r")
|
local file = io.open(filename, "r")
|
||||||
if(file == nil) then
|
if not file then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -78,11 +78,11 @@ end
|
||||||
-- Helper function which saves contents to a file
|
-- Helper function which saves contents to a file
|
||||||
function file_put_contents(filename, contents)
|
function file_put_contents(filename, contents)
|
||||||
local file = io.open(filename, "w+") -- See Lua manual for more information
|
local file = io.open(filename, "w+") -- See Lua manual for more information
|
||||||
if(file == nil) then
|
if not file then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local ret = file:write(contents) == 1
|
local ret = file:write(contents) == true
|
||||||
file:close() -- GC takes care of this if you would've forgotten it
|
file:close() -- GC takes care of this if you would've forgotten it
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue