Verbose logging

This commit is contained in:
Casey 2023-10-12 20:42:25 +03:00
parent 314935401c
commit 56946ee55e
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
3 changed files with 15 additions and 18 deletions

View File

@ -13,17 +13,13 @@ _G.entities = {}
local function run_wrapped(func, filename) local function run_wrapped(func, filename)
return function() return function()
print("Starting module "..filename)
local ok, res = pcall(func) local ok, res = pcall(func)
local oldc = term.getTextColor()
if ok then if ok then
term.setTextColor(colors.blue) print("Module "..filename.." exited: " .. tostring(res))
print("module "..filename.." exited")
else else
term.setTextColor(colors.blue) printErr("Module "..filename.." crashed: " .. res)
print("module "..filename.." crashed: " .. res)
end end
term.setTextColor(oldc)
end end
end end
@ -58,8 +54,9 @@ local function safeset(func, name, old)
end end
print("Running...") print("Running...")
parallel.waitForAll(table.unpack(modules), function() parallel.waitForAll(function()
while true do print("Exit handler started")
while _G._running do
local ev = { os.pullEvent("exit") } local ev = { os.pullEvent("exit") }
if ev[1] == "exit" then if ev[1] == "exit" then
_G._running = false _G._running = false
@ -71,18 +68,14 @@ parallel.waitForAll(table.unpack(modules), function()
end end
end end
end, end,
function() function() -- Neural Interface coroutine
print("NI routine started")
while _G._running do while _G._running do
_G.player = safeset(NI.getMetaOwner, "getMetaOwner()", _G.player) _G.player = safeset(NI.getMetaOwner, "getMetaOwner()", _G.player)
_G.entities = safeset(NI.sense, "sense()", _G.entities) _G.entities = safeset(NI.sense, "sense()", _G.entities)
os.sleep(0.05)
end
end,
function()
while _G._running do
_G.canvas3d.recenter() _G.canvas3d.recenter()
os.sleep(0.05) os.sleep(0.05)
end end
_G.canvas3d_src.clear() _G.canvas3d_src.clear()
end) end, table.unpack(modules))
print("Goodbye!") print("Goodbye!")

View File

@ -4,7 +4,7 @@ return function()
local cubes = {} local cubes = {}
while _G._running do while _G._running do
local el = entities local el = entities
print("found "..#entities.."entities") print("found "..#entities.." entities")
for i, cube in ipairs(cubes) do for i, cube in ipairs(cubes) do
if el[i] == nil then if el[i] == nil then
cube.setSize(0.0, 0.0, 0.0) cube.setSize(0.0, 0.0, 0.0)

View File

@ -15,7 +15,11 @@ local function getFile(url, path)
end end
for i, file in ipairs(files.files) do for i, file in ipairs(files.files) do
getFile(files.repository .. "/" .. file.src, file.path) if type(file) == "string" then
getFile(files.repository .. "/" .. file, file)
else
getFile(files.repository .. "/" .. file.src, file.path)
end
end end
shell.run("main.lua") shell.run("main.lua")