Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal

Leaderboard


Popular Content

Showing content with the highest reputation on 02/19/19 in all areas

  1. 1 point
    I believe I see where you're trying to go with this but I think there is an easier way. Store the reactor proxies as values in a key/value table and then send method names and args to be executed. Here's a simple example.. -- # Reactor server: Recieves commands from remote client to be run local component = require 'component' local event = require 'event' local modem = component.modem modem.open(1040) -- # List of reactors to call methods remotely upon local reactors = { r1 = component.proxy(component.get '0c60c'), r2 = component.proxy(component.get '0ef58'), r3 = component.proxy(component.get '255aa') } repeat -- # pack it all into a table local msg = table.pack(event.pull('modem_message')) -- # the droids we're looking for local reactor, method = msg[6], msg[7] -- # args to call with the remote method (if any) local args = #msg > 7 and table.pack(table.unpack(msg, 8)) or {} -- # if remote reactor id is present then... if reactors[reactor] then -- # execute the method call with args on a specific reactor. guarded for faulty messages with pcall so we dont crash. local result = table.pack(pcall(reactors[reactor][method], table.unpack(args))) print(sting.format("called %s on reactor id %s", method, reactor)) -- # respond to client with result modem.send(msg[2], msg[3], table.unpack(result)) end -- # client can send the message 'exit' to quit or hold Ctrl+C on the server until msg[6] == 'exit' -- # End of server -- # client: Send remote commands to be run on server components -- # A very simple client... Spruce it up as needed local component = require 'component' local event = require 'event' local modem = component.modem modem.open(1040) modem.send(server.address, server.port, 'r1', 'isProcessing') -- # exec 'isProcessing' on 'r1' at server print(event.pull('modem_message', modem.address, server.address, server.port)) -- # print and await server response -- # End of client
  • Newsletter

    Want to keep up to date with all our latest news and information?
    Sign Up
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.