awful.util: use loadfile instead of loadstring

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-09-30 17:00:19 +02:00
parent afbcd681be
commit c3775199b0
1 changed files with 3 additions and 13 deletions

View File

@ -9,6 +9,7 @@ local os = os
local io = io local io = io
local assert = assert local assert = assert
local loadstring = loadstring local loadstring = loadstring
local loadfile = loadfile
local debug = debug local debug = debug
local print = print local print = print
local type = type local type = type
@ -111,23 +112,12 @@ function unescape(text)
end end
--- Check if a file is a Lua valid file. --- Check if a file is a Lua valid file.
-- This is done by loading the content and compiling it with loadstring(). -- This is done by loading the content and compiling it with loadfile().
-- @param path The file path. -- @param path The file path.
-- @return A function if everything is alright, a string with the error -- @return A function if everything is alright, a string with the error
-- otherwise. -- otherwise.
function checkfile(path) function checkfile(path)
if not path then return "E: no file given" end local f, e = loadfile(s)
local f = io.open(path)
if not f then
return "E: unable to open file " .. path
end
local s = f:read("*all")
f:close()
local f, e = loadstring(s)
-- Return function if function, otherwise return error. -- Return function if function, otherwise return error.
if f then return f end if f then return f end
return e return e