Created
October 19, 2016 13:59
-
-
Save deepakjois/e1ca1ca5c4950392366271de0e2e02a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local make_loader = function(path, pos, loadfunc) | |
local default_loader = package.searchers[pos] | |
local loader = function(name) | |
local file, _ = package.searchpath(name,path) | |
if not file then | |
local msg = "\n\t[lualoader] Search failed" | |
local ret = default_loader(name) | |
if type(ret) == "string" then | |
return msg ..ret | |
elseif type(ret) == "nil" then | |
return msg | |
else | |
return ret | |
end | |
end | |
local loader,err = loadfunc(file, name) | |
if not loader then | |
return "\n\t[lualoader] Loading error:\n\t"..err | |
end | |
return loader | |
end | |
package.searchers[pos] = loader | |
end | |
local binary_loader = function(file, name) | |
local symbol = name:gsub("%.","_") | |
return package.loadlib(file, "luaopen_"..symbol) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment