Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@deepakjois
Created October 19, 2016 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deepakjois/e1ca1ca5c4950392366271de0e2e02a7 to your computer and use it in GitHub Desktop.
Save deepakjois/e1ca1ca5c4950392366271de0e2e02a7 to your computer and use it in GitHub Desktop.
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