Fix Modules on Windows (#2)

Modules would not load on Windows because directories are treated differently then they are on Linux. For this reason, io.open() did not suffice to check if a directory existed. This commit makes get_module_path() check for an init.lua file rather than attempting to just check the directory.
This commit is contained in:
octacian 2017-02-03 15:45:17 -08:00
parent af2023b3eb
commit 6cdabc2934

View File

@ -36,7 +36,7 @@ local settings = Settings(modpath.."/modules.conf"):to_table()
function digicompute.get_module_path(name) function digicompute.get_module_path(name)
local module_path = modpath.."/modules/"..name local module_path = modpath.."/modules/"..name
if digicompute.builtin.exists(module_path) then if digicompute.builtin.exists(module_path.."/init.lua") then
return module_path return module_path
end end
end end
@ -44,18 +44,15 @@ end
-- [function] Load module (overrides modules.conf) -- [function] Load module (overrides modules.conf)
function digicompute.load_module(name) function digicompute.load_module(name)
if loaded_modules[name] ~= false then if loaded_modules[name] ~= false then
local module_path = digicompute.get_module_path(name) local module_init = digicompute.get_module_path(name).."/init.lua"
if module_path then if module_init then
if digicompute.builtin.exists(module_path.."/init.lua") then dofile(module_init)
dofile(module_path.."/init.lua") loaded_modules[name] = true
loaded_modules[name] = true return true
return true
else
digicompute.log("Module ("..name..") missing init.lua, could not load", "error")
end
else else
digicompute.log("Invalid module \""..name.."\"", "error") digicompute.log("Invalid module \""..name.."\". The module either does not exist "..
"or is missing an init.lua file.", "error")
end end
else else
return true return true