awful.util: use loadfile instead of loadstring
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
afbcd681be
commit
c3775199b0
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue