OpenComputers Von Neumann Machine Programs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
963 B

local computer = computer or require("computer")
local event = event or require("event")
local modem = component.proxy(component.list("modem")())
local function unknown()
-- do nothing
local http = {}
local http.handlers = setmetatable({}, { __index = function() return unknown end })
local function http.example()
http.handlers["/example"] = function (...)
-- "modem_message", local addr, remote addr, port, distance, "/example"
tmp = {...}
modem.send(tmp[3], tmp[4], "hello world")
local function http.listen(port)
eventID = event.listen("modem_message", function (_, ...)
-- event type, local addr, remote addr, port, distance, msg
tmp = {...}
-- Filter out messages coming from the wrong port
if tmp[3] ~= port then return end
-- Forward message to the correct handler
return eventID