Created
November 9, 2022 10:36
-
-
Save ochaton/e6b5f9415519f1100faf14f51ce346ea to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env tarantool | |
local fio = require 'fio' | |
local soext = (jit.os == "OSX" and "dylib" or "so") | |
local ROCKS_LIB_PATH = '.rocks/lib/tarantool' | |
local ROCKS_LUA_PATH = '.rocks/share/tarantool' | |
local LIB_TEMPLATES = { '?.'..soext, ROCKS_LIB_PATH .. '/?.'..soext } | |
local LUA_TEMPLATES = { '?.lua', '?/init.lua', ROCKS_LUA_PATH .. '/?.lua', ROCKS_LUA_PATH .. '/?/init.lua' } | |
local function uniq(list) | |
local kv = {} | |
local r = {} | |
for _, item in ipairs(list) do | |
if not kv[item] then | |
table.insert(r, item) | |
kv[item]=true | |
end | |
end | |
return r | |
end | |
return function(path) | |
if not path then | |
local file = fio.abspath(debug.getinfo(2, "S").source:sub(2)) | |
local link = fio.readlink(file) | |
if not link then | |
path = fio.dirname(file) | |
elseif link:sub(1, 1) == '/' then | |
-- link to absolute path | |
path = fio.dirname(fio.abspath(link)) | |
else | |
-- link to relative path | |
path = fio.dirname(fio.abspath(fio.pathjoin(fio.dirname(file), link))) | |
end | |
end | |
local root = fio.abspath(path) | |
for _, cfg in ipairs { { 'path', LUA_TEMPLATES }, { 'cpath', LIB_TEMPLATES } } do | |
local paths = {} | |
for _, template in ipairs(cfg[2]) do | |
table.insert(paths, fio.pathjoin(root, template)) | |
end | |
for _, p in ipairs(package[cfg[1]]:gsub(';$', ''):split(';')) do | |
table.insert(paths, p) | |
end | |
package[cfg[1]] = table.concat(uniq(paths), ';') | |
end | |
return root | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment