Created
September 24, 2015 21:07
-
-
Save trajing/24a6b0c71e675c3bb1ec to your computer and use it in GitHub Desktop.
AP2PTP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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