1
0
mirror of https://github.com/kepler155c/opus synced 2024-11-04 16:06:16 +00:00
opus/sys/extensions/6.packages.lua
kepler155c@gmail.com 852bf3f6a6 require order issue
2018-12-30 06:50:59 -05:00

56 lines
1.4 KiB
Lua

_G.requireInjector(_ENV)
local Packages = require('packages')
local Util = require('util')
local fs = _G.fs
local help = _G.help
local shell = _ENV.shell
local appPaths = Util.split(shell.path(), '(.-):')
local luaPaths = Util.split(_G.LUA_PATH, '(.-);')
local helpPaths = Util.split(help.path(), '(.-):')
table.insert(helpPaths, '/sys/help')
local function addEntry(t, e, n)
for _,v in ipairs(t) do
if v == e then
return true
end
end
table.insert(t, n or 1, e)
end
local function addRequirePath(t, path)
addEntry(t, string.format('/%s/?/init.lua', path), 7)
addEntry(t, string.format('/%s/?.lua', path), 7)
addEntry(t, string.format('/%s/?', path), 7)
end
for name in pairs(Packages:installed()) do
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
end
addEntry(appPaths, packageDir)
local apiPath = fs.combine(fs.combine('packages', name), 'apis')
if fs.exists(apiPath) then
addRequirePath(luaPaths, apiPath)
end
local helpPath = '/' .. fs.combine(fs.combine('packages', name), 'help')
if fs.exists(helpPath) then
table.insert(helpPaths, helpPath)
end
end
help.setPath(table.concat(helpPaths, ':'))
shell.setPath(table.concat(appPaths, ':'))
_G.LUA_PATH = table.concat(luaPaths, ';')