Skip to content

Instantly share code, notes, and snippets.

@trajing
Created September 24, 2015 21:07
Show Gist options
  • Select an option

  • Save trajing/24a6b0c71e675c3bb1ec to your computer and use it in GitHub Desktop.

Select an option

Save trajing/24a6b0c71e675c3bb1ec to your computer and use it in GitHub Desktop.
AP2PTP
function init(modemBinding, starterChannel, nextChannelFn)
modemBinding.open(starterChannel)
local stateTable = {
modemBinding = modemBinding,
chan = starterChannel,
nextfn = nextChannelFn
}
return stateTable -- Until I can figure out metatables, this will be strictly function-based.
end
function listen(tbl)
local a, side, from, reply, message, distance = os.pullEvent("modem_message")
tbl.modemBinding.close(tbl.chan)
tbl.chan = reply
tbl.modemBinding.open(tbl.chan)
return side, from, reply, message, distance
end
function transmit(tbl, msg)
nextChannel = tbl.nextfn(tbl.chan, msg)
tbl.modemBinding.transmit(tbl.chan, nextChannel, msg)
tbl.chan = nextChannel
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment