Allow modules to specify an explicit directory, i.e. require("build/mymodule")

This makes it easier to distribute modules along with a project's source code, giving full control over where the modules are kept in the tree.
This commit is contained in:
Jason Perkins 2015-02-06 15:38:56 -05:00
parent 8ecf4ac7f0
commit 25e1e766ae

View File

@ -159,8 +159,18 @@
---
function p.main.moduleLoader(name)
local shortName = name .. "/" .. name .. ".lua"
local dir = path.getdirectory(name)
local name = path.getname(name)
if dir ~= "." then
dir = dir .. "/" .. name
else
dir = name
end
local shortName = dir .. "/" .. name .. ".lua"
local longName = "modules/" .. shortName
local chunk = loadfile(longName) or loadfile(shortName)
if chunk then
return chunk