2018-10-21 00:35:48 +00:00
|
|
|
_G.requireInjector(_ENV)
|
|
|
|
|
|
|
|
local Packages = require('packages')
|
|
|
|
local Util = require('util')
|
|
|
|
|
|
|
|
local shell = _ENV.shell
|
|
|
|
local fs = _G.fs
|
|
|
|
|
2018-12-17 03:17:19 +00:00
|
|
|
local appPaths = Util.split(shell.path(), '(.-);')
|
|
|
|
local luaPaths = Util.split(_G.LUA_PATH, '(.-);')
|
2018-10-21 00:35:48 +00:00
|
|
|
|
2018-12-17 03:17:19 +00:00
|
|
|
local function addPath(t, path)
|
|
|
|
local function addEntry(e)
|
2018-10-21 00:35:48 +00:00
|
|
|
for _,v in ipairs(t) do
|
|
|
|
if v == e then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
table.insert(t, 1, e)
|
|
|
|
end
|
2018-12-17 03:17:19 +00:00
|
|
|
addEntry(string.format('/%s/?', path))
|
|
|
|
addEntry(string.format('/%s/?.lua', path))
|
|
|
|
addEntry(string.format('/%s/?/init.lua', path))
|
2018-10-21 00:35:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- dependency graph
|
|
|
|
-- https://github.com/mpeterv/depgraph/blob/master/src/depgraph/init.lua
|
|
|
|
|
2018-11-04 18:00:37 +00:00
|
|
|
for name in pairs(Packages:installed()) do
|
2018-11-03 22:13:41 +00:00
|
|
|
local packageDir = fs.combine('packages', name)
|
|
|
|
if fs.exists(fs.combine(packageDir, '.install')) then
|
|
|
|
local install = Util.readTable(fs.combine(packageDir, '.install'))
|
|
|
|
if install and install.mount then
|
|
|
|
fs.mount(table.unpack(Util.matches(install.mount)))
|
|
|
|
end
|
2018-10-21 00:35:48 +00:00
|
|
|
end
|
|
|
|
|
2018-11-03 22:13:41 +00:00
|
|
|
addPath(appPaths, packageDir)
|
2018-10-21 08:46:40 +00:00
|
|
|
local apiPath = fs.combine(fs.combine('packages', name), 'apis')
|
|
|
|
if fs.exists(apiPath) then
|
|
|
|
addPath(luaPaths, apiPath)
|
|
|
|
end
|
2018-10-21 00:35:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
shell.setPath(table.concat(appPaths, ':'))
|
2018-12-17 03:17:19 +00:00
|
|
|
_G.LUA_PATH = table.concat(luaPaths, ';')
|