refactor: improve code
This commit is contained in:
@@ -20,15 +20,15 @@ require("silk.core.std")
|
||||
|
||||
-- global helper functions for lua page script
|
||||
function has_module(m)
|
||||
if utils.file_exists(__ROOT__ .. '/' .. m) then
|
||||
if ulib.exists(__ROOT__ .. '/' .. m) then
|
||||
if m:find("%.ls$") then
|
||||
return true, true, __ROOT__ .. '/' .. m
|
||||
else
|
||||
return true, false, m:gsub(".lua$", "")
|
||||
end
|
||||
elseif utils.file_exists(__ROOT__ .. '/' .. string.gsub(m, '%.', '/') .. '.lua') then
|
||||
elseif ulib.exists(__ROOT__ .. '/' .. string.gsub(m, '%.', '/') .. '.lua') then
|
||||
return true, false, m
|
||||
elseif utils.file_exists(__ROOT__ .. '/' .. string.gsub(m, '%.', '/') .. '.ls') then
|
||||
elseif ulib.exists(__ROOT__ .. '/' .. string.gsub(m, '%.', '/') .. '.ls') then
|
||||
return true, true, __ROOT__ .. '/' .. string.gsub(m, '%.', '/') .. '.ls'
|
||||
end
|
||||
return false, false, nil
|
||||
|
||||
@@ -86,10 +86,11 @@ function utils.unescape(s)
|
||||
return str
|
||||
end
|
||||
|
||||
function utils.file_exists(name)
|
||||
function ulib.exists(name)
|
||||
local f = io.open(name, "r")
|
||||
if f ~= nil then
|
||||
io.close(f)
|
||||
if f then
|
||||
f:close()
|
||||
--io.close(f)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user