Binary Modules Loader |
|
module(..., package.seeall) local function load(modulename) local errmsg = "" -- Find DLL local symbolname = string.gsub(modulename, "%.", "_") local modulepath = string.gsub(modulename, "%.", "/") for path in string.gmatch(package.cpath, "([^;]+)") do local filename = string.gsub(path, "%?", modulepath) local file = io.open(filename, "rb") if file then file:close() -- Load and return the module loader local loader,msg = package.loadlib(filename, "luaopen_"..symbolname) if not loader then error("error loading module '"..modulename.."' from file '"..path.."':\n\t"..msg, 3) end return loader 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 binary loader table.insert(package.loaders, 3, load)