1
0

Implemented lazy load of platform specific functionallity, and a different test for that functionallity.

This commit is contained in:
Jon Michael Aanes 2018-01-09 13:29:15 +01:00
parent 81626f6b1e
commit 9b284ee2ce

View File

@ -56,24 +56,32 @@ local function package_config ()
} }
end end
local iterate_files_in_subfiles local iterate_files_in_subfiles = function (...)
-- This outer function is a wrapper, that lazily loads the correct
-- version of the iterate function, based on the availability of
-- the commands.
if package_config().dir_sep == '/' then if os.execute 'find -false' == 0 then
function iterate_files_in_subfiles (root_path) iterate_files_in_subfiles = function (root_path)
-- On unix -- On unix
-- Use `find` to find files in folders below the given matching. -- Use `find` to find files in folders below the given matching.
assert(type(root_path) == 'string') assert(type(root_path) == 'string')
local start_directory = root_path:match '^(.-)?' or root_path local start_directory = root_path:match '^(.-)?' or root_path
local pfile = io.popen ('find -L "'..start_directory..'" -type f ! -path \'*/\\.*\' -print0 2> /dev/null') local pfile = io.popen ('find -L "'..start_directory..'" -type f ! -path \'*/\\.*\' -print0 2> /dev/null')
local list_str = pfile:read '*all' local list_str = pfile:read '*all'
pfile:close() pfile:close()
return list_str:gmatch '[^%z]+' return list_str:gmatch '[^%z]+'
end
else
-- Other platforms
error '[suggest-require]: Your platform does not possess the "find" utility, and is thus not currently supported.'
end end
else
-- On windows -----
error '[suggest-require]: Windows is not currently supported.'
return iterate_files_in_subfiles(...)
end end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -199,7 +207,7 @@ local function get_available_module_names ()
for name in pairs(dedub) do module_names[#module_names+1] = name end for name in pairs(dedub) do module_names[#module_names+1] = name end
table.sort(module_names) table.sort(module_names)
-- Output assertions -- Assert that output is correctly formatted
assert(type(module_names) == 'table') assert(type(module_names) == 'table')
for i = 1, #module_names do for i = 1, #module_names do
assert(type(module_names[i]) == 'string') assert(type(module_names[i]) == 'string')