computercraft/client
2021-01-09 03:24:02 +01:00

48 lines
1.4 KiB
Plaintext

function dump(o)
if o == nil then
return ""
end
if type(o) == 'table' then
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '['..k..'] = ' .. dump(v) .. ','
end
return s .. '} '
end
return tostring(o)
end
rednet.open("left")
rednet.host("rmm", "t0-turtle01")
local master = rednet.lookup("rmm", "master")
while true do
local event, id, data = os.pullEvent()
if event == "rednet_message" then
print(id .. " (" .. event .. ")> " .. dump(data))
if type(data) == 'table' then
if data[1] == 'eval' then
local cmd_fn, err = loadstring(data[2])
if not cmd_fn then
print("Compile error:" .. err)
rednet.send(master, "Compile error:" .. err)
else
local success, output = pcall(cmd_fn)
if success then
if output then
print("Command output: " .. dump(output))
rednet.send(master, "Command output: " .. dump(output))
end
else
print("Runtime error:" .. output)
rednet.send(master, "Runtime error:" .. output)
end
end
end
end
end
end