diff --git a/apis/blocks.lua b/apis/blocks.lua index ce1d91d..af2f61b 100644 --- a/apis/blocks.lua +++ b/apis/blocks.lua @@ -42,8 +42,7 @@ local blockDB = TableDB() function blockDB:load() - local dir = fs.getDir(shell.getRunningProgram()) - local blocks = JSON.decodeFromFile(fs.combine(dir, 'etc/blocks.json')) + local blocks = JSON.decodeFromFile('usr/etc/blocks.json')) if not blocks then error('Unable to read blocks.json') diff --git a/apps/builder.lua b/apps/builder.lua index 020fb1b..f4a1dbb 100644 --- a/apps/builder.lua +++ b/apps/builder.lua @@ -3,7 +3,6 @@ if not turtle and not commands then end requireInjector(getfenv(1)) -package.path = package.path .. ':/' .. fs.getDir(shell.getRunningProgram()) .. '/apis' local Blocks = require('blocks') local class = require('class') diff --git a/apps/trace.lua b/apps/trace.lua new file mode 100644 index 0000000..ca79b6e --- /dev/null +++ b/apps/trace.lua @@ -0,0 +1,52 @@ +local args = {...} + +if not args[1] then + print("Usage:") + print(shell.getRunningProgram() .. " [program arguments, ...]") + return +end + +local path = shell.resolveProgram(args[1]) or shell.resolve(args[1]) + +-- here be dragons +if fs.exists(path) then + local eshell = setmetatable({getRunningProgram=function() return path end}, {__index = shell}) + local env = setmetatable({shell=eshell}, {__index=_ENV}) + + local f = fs.open(path, "r") + local d = f.readAll() + f.close() + + local func, e = load(d, fs.getName(path), nil, env) + if not func then + printError("Syntax error:") + printError(" " .. e) + else + table.remove(args, 1) + xpcall(function() func(unpack(args)) end, function(err) + local trace = {} + local i, hitEnd, _, e = 4, false + repeat + _, e = pcall(function() error("", i) end) + i = i + 1 + if e == "xpcall: " then + hitEnd = true + break + end + table.insert(trace, e) + until i > 10 + table.remove(trace) + if err:match("^" .. trace[1]:match("^(.-:%d+)")) then table.remove(trace, 1) end + printError("\nProgram has crashed! Stack trace:") + printError(err) + for i, v in ipairs(trace) do + printError(" at " .. v:match("^(.-:%d+)")) + end + if not hitEnd then + printError(" ...") + end + end) + end +else + printError("program not found") +end diff --git a/apps/webapp.lua b/apps/webapp.lua new file mode 100644 index 0000000..883de3f --- /dev/null +++ b/apps/webapp.lua @@ -0,0 +1,52 @@ +local args = { ... } +local GIT_REPO = 'kepler155c/opus/develop' +local BASE = 'https://raw.githubusercontent.com/' .. GIT_REPO + +local function dourl(env, url) + local h = http.get(url) + if h then + local fn, m = load(h.readAll(), url, nil, env) + h.close() + if fn then + return fn() + end + end + error('Failed to download ' .. url) +end + +local s, m = pcall(function() + + _G.requireInjector = dourl(getfenv(1), BASE .. '/sys/apis/injector.lua') + + local function mkenv() + local env = { } + for k,v in pairs(getfenv(1)) do + env[k] = v + end + setmetatable(env, { __index = _G }) + return env + end + + -- install vfs + dourl(mkenv(), BASE .. '/sys/extensions/vfs.lua') + + -- install filesystem + fs.mount('', 'gitfs', GIT_REPO) + fs.mount('usr', 'gitfs', 'kepler155c/opus-apps/develop') + + -- start program + local file = table.remove(args, 1) + + local s, m = os.run(mkenv(), file or 'startup', unpack(args)) + if not s and m then + error(m) + end +end) + +if not s and m then + printError(m) +end + +if fs.restore then + fs.restore() +end diff --git a/etc/scripts/update b/etc/scripts/update index 484beb1..66522e1 100644 --- a/etc/scripts/update +++ b/etc/scripts/update @@ -1 +1 @@ -shell.run('/apps/update.lua') +shell.run('http://pastebin.com/raw/sj4VMVJj automatic')