Lua Modules Loader |
|
module(..., package.seeall) local function load(modulename) local errmsg = "" -- Find source local modulepath = string.gsub(modulename, "%.", "/") for path in string.gmatch(package.path, "([^;]+)") do local filename = string.gsub(path, "%?", modulepath) local file = io.open(filename, "rb") if file then -- Compile and return the module return assert(loadstring(assert(file:read("*a")), filename)) end errmsg = errmsg.."\n\tno file '"..filename.."' (checked with custom loader)" end return errmsg end -- Install the loader so that it's called just before the normal Lua loader table.insert(package.loaders, 2, load)