mirror of
https://github.com/kepler155c/opus
synced 2025-10-19 09:47:39 +00:00
fix lua path, mwm, cleanup injector
This commit is contained in:
@@ -23,8 +23,6 @@ table.insert(luaPaths, 5, '/sys/apis/?.lua')
|
||||
table.insert(luaPaths, 6, '/sys/apis/?/init.lua')
|
||||
|
||||
local DEFAULT_PATH = table.concat(luaPaths, ';')
|
||||
local DEFAULT_BRANCH = _ENV.OPUS_BRANCH or _G.OPUS_BRANCH or 'develop-1.8'
|
||||
local DEFAULT_UPATH = GIT_URL .. '/kepler155c/opus/' .. DEFAULT_BRANCH .. '/sys/apis'
|
||||
|
||||
local fs = _G.fs
|
||||
local http = _G.http
|
||||
@@ -32,7 +30,7 @@ local os = _G.os
|
||||
local string = _G.string
|
||||
|
||||
if not http._patched then
|
||||
-- fix broken http get
|
||||
-- fix broken http get (http.get is not coroutine safe)
|
||||
local syncLocks = { }
|
||||
|
||||
local function sync(obj, fn)
|
||||
@@ -110,6 +108,12 @@ return function(env)
|
||||
end
|
||||
if fs.exists(sPath) and not fs.isDir(sPath) then
|
||||
return loadfile(sPath, env)
|
||||
elseif sPath:match("^(https?:)") then
|
||||
print('loading ' .. sPath)
|
||||
local c = loadUrl(sPath)
|
||||
if c then
|
||||
return load(c, modname, nil, env)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -138,24 +142,9 @@ return function(env)
|
||||
end
|
||||
end
|
||||
|
||||
local function urlSearcher(modname)
|
||||
local fname = modname:gsub('%.', '/') .. '.lua'
|
||||
|
||||
if fname:sub(1, 1) ~= '/' then
|
||||
for entry in string.gmatch(env.package.upath, "[^;]+") do
|
||||
local url = entry .. '/' .. fname
|
||||
local c = loadUrl(url)
|
||||
if c then
|
||||
return load(c, modname, nil, env)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- place package and require function into env
|
||||
env.package = {
|
||||
path = env.LUA_PATH or _G.LUA_PATH or DEFAULT_PATH,
|
||||
upath = env.LUA_UPATH or _G.LUA_UPATH or DEFAULT_UPATH,
|
||||
config = '/\n:\n?\n!\n-',
|
||||
preload = { },
|
||||
loaded = {
|
||||
@@ -172,7 +161,6 @@ return function(env)
|
||||
pathSearcher,
|
||||
pastebinSearcher,
|
||||
gitSearcher,
|
||||
urlSearcher,
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -28,6 +28,8 @@ function Terminal.window(parent, sx, sy, w, h, isVisible)
|
||||
})
|
||||
canvas.offy = 0
|
||||
|
||||
win.canvas = canvas
|
||||
|
||||
local function update()
|
||||
if isVisible then
|
||||
canvas:render(parent)
|
||||
@@ -98,6 +100,16 @@ function Terminal.window(parent, sx, sy, w, h, isVisible)
|
||||
end
|
||||
win.setTextColour = win.setTextColor
|
||||
|
||||
function win.getPaletteColor(n)
|
||||
return parent.getPaletteColor(n)
|
||||
end
|
||||
win.getPaletteColour = win.getPaletteColor
|
||||
|
||||
function win.setPaletteColor(n, r, g, b)
|
||||
return parent.setPaletteColor(n, r, g, b)
|
||||
end
|
||||
win.setPaletteColour = win.setPaletteColor
|
||||
|
||||
function win.setBackgroundColor(c)
|
||||
bg = c
|
||||
end
|
||||
|
97
sys/apis/trace.lua
Normal file
97
sys/apis/trace.lua
Normal file
@@ -0,0 +1,97 @@
|
||||
-- stack trace by SquidDev (MIT License)
|
||||
-- https://raw.githubusercontent.com/SquidDev-CC/mbs/master/lib/stack_trace.lua
|
||||
|
||||
local type = type
|
||||
local debug_traceback = type(debug) == "table" and type(debug.traceback) == "function" and debug.traceback
|
||||
|
||||
local function traceback(x)
|
||||
-- Attempt to detect error() and error("xyz", 0).
|
||||
-- This probably means they're erroring the program intentionally and so we
|
||||
-- shouldn't display anything.
|
||||
if x == nil or (type(x) == "string" and not x:find(":%d+:")) then
|
||||
return x
|
||||
end
|
||||
|
||||
if debug_traceback then
|
||||
-- The parens are important, as they prevent a tail call occuring, meaning
|
||||
-- the stack level is preserved. This ensures the code behaves identically
|
||||
-- on LuaJ and PUC Lua.
|
||||
return (debug_traceback(tostring(x), 2))
|
||||
else
|
||||
local level = 3
|
||||
local out = { tostring(x), "stack traceback:" }
|
||||
while true do
|
||||
local _, msg = pcall(error, "", level)
|
||||
if msg == "" then break end
|
||||
|
||||
out[#out + 1] = " " .. msg
|
||||
level = level + 1
|
||||
end
|
||||
|
||||
return table.concat(out, "\n")
|
||||
end
|
||||
end
|
||||
|
||||
local function trim_traceback(target, marker)
|
||||
local ttarget, tmarker = {}, {}
|
||||
for line in target:gmatch("([^\n]*)\n?") do ttarget[#ttarget + 1] = line end
|
||||
for line in marker:gmatch("([^\n]*)\n?") do tmarker[#tmarker + 1] = line end
|
||||
|
||||
-- Trim identical suffixes
|
||||
local t_len, m_len = #ttarget, #tmarker
|
||||
while t_len >= 3 and ttarget[t_len] == tmarker[m_len] do
|
||||
table.remove(ttarget, t_len)
|
||||
t_len, m_len = t_len - 1, m_len - 1
|
||||
end
|
||||
|
||||
-- Trim elements from this file and xpcall invocations
|
||||
while t_len >= 1 and ttarget[t_len]:find("^\tstack_trace%.lua:%d+:") or
|
||||
ttarget[t_len] == "\t[C]: in function 'xpcall'" or ttarget[t_len] == " xpcall: " do
|
||||
table.remove(ttarget, t_len)
|
||||
t_len = t_len - 1
|
||||
end
|
||||
|
||||
return ttarget
|
||||
end
|
||||
|
||||
--- Run a function with
|
||||
return function (fn, ...)
|
||||
-- So this is rather grim: we need to get the full traceback and current one and remove
|
||||
-- the common prefix
|
||||
local trace
|
||||
local args = { ... }
|
||||
|
||||
-- xpcall in Lua 5.1 does not accept parameters
|
||||
-- which is not ideal
|
||||
local res = table.pack(xpcall(function()
|
||||
return fn(table.unpack(args))
|
||||
end, traceback))
|
||||
|
||||
if not res[1] then
|
||||
trace = traceback("trace.lua:1:")
|
||||
end
|
||||
local ok, err = res[1], res[2]
|
||||
|
||||
if not ok and err ~= nil then
|
||||
trace = trim_traceback(err, trace)
|
||||
|
||||
-- Find the position where the stack traceback actually starts
|
||||
local trace_starts
|
||||
for i = #trace, 1, -1 do
|
||||
if trace[i] == "stack traceback:" then trace_starts = i; break end
|
||||
end
|
||||
|
||||
-- If this traceback is more than 15 elements long, keep the first 9, last 5
|
||||
-- and put an ellipsis between the rest
|
||||
local max = 12
|
||||
if trace_starts and #trace - trace_starts > max then
|
||||
local keep_starts = trace_starts + 9
|
||||
for i = #trace - trace_starts - max, 0, -1 do table.remove(trace, keep_starts + i) end
|
||||
table.insert(trace, keep_starts, " ...")
|
||||
end
|
||||
|
||||
return false, table.concat(trace, "\n")
|
||||
end
|
||||
|
||||
return table.unpack(res, 1, res.n)
|
||||
end
|
@@ -246,17 +246,17 @@ function Canvas:blitClipped(device, offset)
|
||||
end
|
||||
|
||||
function Canvas:redraw(device)
|
||||
--[[
|
||||
-- self:dirty()
|
||||
-- self:render(device)
|
||||
if #self.layers > 0 then
|
||||
for _,layer in pairs(self.layers) do
|
||||
self:punch(layer)
|
||||
end
|
||||
self:blitClipped(device)
|
||||
else
|
||||
self:blit(device)
|
||||
self:renderLayers(device)
|
||||
end
|
||||
self:clean()
|
||||
]]
|
||||
end
|
||||
|
||||
function Canvas:isDirty()
|
||||
@@ -384,61 +384,4 @@ function Canvas:applyPalette(palette)
|
||||
self.palette = palette
|
||||
end
|
||||
|
||||
function Canvas.convertWindow(win, parent, wx, wy)
|
||||
local w, h = win.getSize()
|
||||
|
||||
win.canvas = Canvas({
|
||||
x = wx,
|
||||
y = wy,
|
||||
width = w,
|
||||
height = h,
|
||||
isColor = win.isColor(),
|
||||
})
|
||||
|
||||
function win.clear()
|
||||
win.canvas:clear(win.getBackgroundColor(), win.getTextColor())
|
||||
end
|
||||
|
||||
function win.clearLine()
|
||||
local _, y = win.getCursorPos()
|
||||
win.canvas:write(1,
|
||||
y,
|
||||
_rep(' ', win.canvas.width),
|
||||
win.getBackgroundColor(),
|
||||
win.getTextColor())
|
||||
end
|
||||
|
||||
function win.write(str)
|
||||
local x, y = win.getCursorPos()
|
||||
win.canvas:write(x,
|
||||
y,
|
||||
str,
|
||||
win.getBackgroundColor(),
|
||||
win.getTextColor())
|
||||
win.setCursorPos(x + #str, y)
|
||||
end
|
||||
|
||||
function win.blit(text, fg, bg)
|
||||
local x, y = win.getCursorPos()
|
||||
win.canvas:blit(x, y, text, bg, fg)
|
||||
end
|
||||
|
||||
function win.redraw()
|
||||
win.canvas:redraw(parent)
|
||||
end
|
||||
|
||||
function win.scroll(n)
|
||||
table.insert(win.canvas.lines, table.remove(win.canvas.lines, 1))
|
||||
win.canvas.lines[#win.canvas.lines].text = _rep(' ', win.canvas.width)
|
||||
win.canvas:dirty()
|
||||
end
|
||||
|
||||
function win.reposition(x, y, width, height)
|
||||
win.canvas.x, win.canvas.y = x, y
|
||||
win.canvas:resize(width or win.canvas.width, height or win.canvas.height)
|
||||
end
|
||||
|
||||
win.clear()
|
||||
end
|
||||
|
||||
return Canvas
|
||||
|
Reference in New Issue
Block a user