reorganization

This commit is contained in:
kepler155c
2017-09-15 20:28:00 -04:00
parent d45b375678
commit b4d3160cd8
5 changed files with 106 additions and 4 deletions

View File

@@ -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')

View File

@@ -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')

52
apps/trace.lua Normal file
View File

@@ -0,0 +1,52 @@
local args = {...}
if not args[1] then
print("Usage:")
print(shell.getRunningProgram() .. " <program> [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("<tracemarker>", i) end)
i = i + 1
if e == "xpcall: <tracemarker>" 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

52
apps/webapp.lua Normal file
View File

@@ -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

View File

@@ -1 +1 @@
shell.run('/apps/update.lua')
shell.run('http://pastebin.com/raw/sj4VMVJj automatic')