style: Enhance eval response handling and inventory update for improved data management

This commit is contained in:
MayaTheShy
2026-02-20 02:47:29 -05:00
parent 7dae800eed
commit 617310eade

View File

@@ -281,13 +281,25 @@ local function executeEval(uuid, code)
return
end
local ok, result = pcall(fn)
local results = table.pack(pcall(fn))
local ok = results[1]
if ok then
local returnVal
if results.n <= 2 then
-- Single return value
returnVal = results[2]
else
-- Multiple return values - pack into array
returnVal = {}
for i = 2, results.n do
returnVal[i - 1] = results[i]
end
end
modem.transmit(CHANNEL_SEND, CHANNEL_RECEIVE, {
type = "eval_response",
uuid = uuid,
result = result,
result = returnVal,
error = nil,
turtleID = os.getComputerID()
})
@@ -296,7 +308,7 @@ local function executeEval(uuid, code)
type = "eval_response",
uuid = uuid,
result = nil,
error = "Runtime error: " .. tostring(result),
error = "Runtime error: " .. tostring(results[2]),
turtleID = os.getComputerID()
})
end
@@ -650,16 +662,16 @@ parallel.waitForAny(
while true do
os.pullEvent("turtle_inventory")
local inventory = {}
local fns = {}
for i = 1, 16 do
fns[i] = function()
local item = turtle.getItemDetail(i, true)
if item then
inventory[tostring(i)] = item
end
local item = turtle.getItemDetail(i)
if item then
table.insert(inventory, {
slot = i,
name = item.name,
count = item.count
})
end
end
parallel.waitForAll(table.unpack(fns))
modem.transmit(CHANNEL_SEND, CHANNEL_RECEIVE, {
type = "inventory_update",