1
0
mirror of https://github.com/kepler155c/opus synced 2025-01-05 21:30:28 +00:00

require rework round 3

This commit is contained in:
kepler155c@gmail.com 2019-01-26 22:58:02 -05:00
parent 496e95a6c4
commit b320c92551
4 changed files with 24 additions and 44 deletions

View File

@ -15,12 +15,12 @@ for i = 1, #luaPaths do
end end
end end
table.insert(luaPaths, 1, '?') table.insert(luaPaths, 1, '?.lua')
table.insert(luaPaths, 2, '?.lua') table.insert(luaPaths, 2, '?/init.lua')
table.insert(luaPaths, 3, '/usr/apis/?') table.insert(luaPaths, 3, '/usr/apis/?.lua')
table.insert(luaPaths, 4, '/usr/apis/?.lua') table.insert(luaPaths, 4, '/usr/apis/?/init.lua')
table.insert(luaPaths, 5, '/sys/apis/?') table.insert(luaPaths, 5, '/sys/apis/?.lua')
table.insert(luaPaths, 6, '/sys/apis/?.lua') table.insert(luaPaths, 6, '/sys/apis/?/init.lua')
local DEFAULT_PATH = table.concat(luaPaths, ';') local DEFAULT_PATH = table.concat(luaPaths, ';')
local DEFAULT_BRANCH = _ENV.OPUS_BRANCH or _G.OPUS_BRANCH or 'develop-1.8' local DEFAULT_BRANCH = _ENV.OPUS_BRANCH or _G.OPUS_BRANCH or 'develop-1.8'
@ -82,13 +82,15 @@ end
-- Add require and package to the environment -- Add require and package to the environment
return function(env) return function(env)
local function standardSearcher(modname) local function preloadSearcher(modname)
-- Should this be 2 diff searchers ? if yes, installer would need an update
if env.package.preload[modname] then if env.package.preload[modname] then
return function() return function()
return env.package.preload[modname](modname, env) return env.package.preload[modname](modname, env)
end end
end end
end
local function loadedSearcher(modname)
if env.package.loaded[modname] then if env.package.loaded[modname] then
return function() return function()
return env.package.loaded[modname] return env.package.loaded[modname]
@ -96,40 +98,20 @@ return function(env)
end end
end end
local function shellSearcher(modname)
local fname = modname:gsub('%.', '/') .. '.lua'
if env.shell and type(env.shell.getRunningProgram) == 'function' then
local running = env.shell.getRunningProgram()
if running then
local path = fs.combine(fs.getDir(running), fname)
if fs.exists(path) and not fs.isDir(path) then
return loadfile(path, env)
end
end
end
end
local function pathSearcher(modname) local function pathSearcher(modname)
local fname = modname:gsub('%.', '/') local fname = modname:gsub('%.', '/')
for pattern in string.gmatch(env.package.path, "[^;]+") do for pattern in string.gmatch(env.package.path, "[^;]+") do
local sPath = string.gsub(pattern, "%?", fname) local sPath = string.gsub(pattern, "%?", fname)
if env.shell and env.shell.dir and sPath:sub(1, 1) ~= "/" then -- TODO: if there's no shell, we should not be checking relative paths below
sPath = fs.combine(env.shell.dir(), sPath) -- as they will resolve to root directory
if env.shell and type(env.shell.getRunningProgram) == 'function' and sPath:sub(1, 1) ~= "/" then
sPath = fs.combine(fs.getDir(env.shell.getRunningProgram()), sPath)
end end
if fs.exists(sPath) and not fs.isDir(sPath) then if fs.exists(sPath) and not fs.isDir(sPath) then
return loadfile(sPath, env) return loadfile(sPath, env)
end end
end end
--[[
for dir in string.gmatch(env.package.path, "[^:]+") do
local path = fs.combine(dir, fname)
if fs.exists(path) and not fs.isDir(path) then
return loadfile(path, env)
end
end
]]
end end
-- require('BniCQPVf') -- require('BniCQPVf')
@ -185,8 +167,8 @@ return function(env)
table = table, table = table,
}, },
loaders = { loaders = {
standardSearcher, preloadSearcher,
shellSearcher, loadedSearcher,
pathSearcher, pathSearcher,
pastebinSearcher, pastebinSearcher,
gitSearcher, gitSearcher,

View File

@ -41,9 +41,10 @@ local page = UI.Page {
--{ text = 'Chat', event = 'chat' }, --{ text = 'Chat', event = 'chat' },
{ text = 'Trust', dropdown = { { text = 'Trust', dropdown = {
{ text = 'Establish', event = 'trust' }, { text = 'Establish', event = 'trust' },
{ text = 'Remove', event = 'untrust' }, -- { text = 'Remove', event = 'untrust' },
} }, } },
{ text = 'Help', event = 'help', noCheck = true }, { text = 'Help', event = 'help', noCheck = true },
--[[
{ {
text = '\187', text = '\187',
x = -3, x = -3,
@ -53,6 +54,7 @@ local page = UI.Page {
{ text = 'Show trusted', event = 'show_trusted', noCheck = true }, { text = 'Show trusted', event = 'show_trusted', noCheck = true },
}, },
}, },
]]
}, },
}, },
grid = UI.ScrollingGrid { grid = UI.ScrollingGrid {

View File

@ -44,6 +44,8 @@ for _, v in pairs(Util.split(shell.path(), '(.-):')) do
end end
shell.setPath(table.concat(path, ':')) shell.setPath(table.concat(path, ':'))
_G.LUA_PATH = config.lua_path -- TODO: replace when stable (old lua path is now incorrect)
-- _G.LUA_PATH = config.lua_path
_G.LUA_PATH = package.path
fs.loadTab('usr/config/fstab') fs.loadTab('usr/config/fstab')

View File

@ -24,12 +24,6 @@ local function addEntry(t, e, n)
table.insert(t, n or 1, e) table.insert(t, n or 1, e)
end 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 for name in pairs(Packages:installed()) do
local packageDir = fs.combine('packages', name) local packageDir = fs.combine('packages', name)
if fs.exists(fs.combine(packageDir, '.install')) then if fs.exists(fs.combine(packageDir, '.install')) then
@ -42,7 +36,7 @@ for name in pairs(Packages:installed()) do
addEntry(appPaths, packageDir) addEntry(appPaths, packageDir)
local apiPath = fs.combine(fs.combine('packages', name), 'apis') local apiPath = fs.combine(fs.combine('packages', name), 'apis')
if fs.exists(apiPath) then if fs.exists(apiPath) then
addRequirePath(luaPaths, apiPath) fs.mount(fs.combine('sys/apis', name), 'linkfs', apiPath)
end end
local helpPath = '/' .. fs.combine(fs.combine('packages', name), 'help') local helpPath = '/' .. fs.combine(fs.combine('packages', name), 'help')