Last active
September 9, 2016 11:32
-
-
Save igorcoding/d7f8ed7e9ae104c4327edabd5a23f0dc 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 function alter_package_path(paths, base)local isroot=function(s)return string.sub(s,1,1)=='/'end;local slashends=function(s)return string.sub(s,-1,-1)=='/'end;local fio=require('fio');local bf=debug.getinfo(2,"S").source:sub(2);local lb=fio.readlink(bf);if lb~=nil then bf=lb end;local b=bf:match("(.*/)");if not isroot(b) then b=fio.abspath(b);if not slashends(b)then b=b..'/'end;end;if base~=nil and base~="" then if isroot(base) then b=base;else b=b..base..'/';end;end;local pkg='';for _,p in ipairs(paths)do if isroot(p) then pkg=pkg..";"..p;else pkg = pkg..";"..b..p;end;end;package.path=package.path..pkg;return b;end | |
local base = alter_package_path({ | |
'?.lua', | |
'?/init.lua', | |
'libs/tnt-luas16/?.lua', | |
}) | |
-- Full function here: | |
local function alter_package_path(paths, base) | |
local isroot=function(s)return string.sub(s,1,1)=='/'end; | |
local slashends=function(s)return string.sub(s,-1,-1)=='/'end; | |
local fio=require('fio'); | |
local bf=debug.getinfo(2,"S").source:sub(2); | |
local lb=fio.readlink(bf); | |
if lb~=nil then | |
bf=lb | |
end; | |
local b=bf:match("(.*/)"); | |
if not isroot(b) then | |
b=fio.abspath(b); | |
if not slashends(b)then | |
b=b..'/' | |
end; | |
end; | |
if base~=nil and base~="" then | |
if isroot(base) then | |
b=base; | |
else | |
b=b..base..'/'; | |
end; | |
end; | |
local pkg=''; | |
for _,p in ipairs(paths)do | |
if isroot(p) then | |
pkg=pkg..";"..p; | |
else | |
pkg = pkg..";"..b..p; | |
end; | |
end; | |
package.path=package.path..pkg; | |
return b; | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment