`oc-basecontrol` is a library for distributed base control systems in OpenComputers.
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.
Rahix 20c8c7426f
Make oc-basecontrol more robust
9 years ago
.gitignore Add gitignore 9 years ago
README.md Add test to readme 9 years ago
_bc_backend.lua First part of rewrite 9 years ago
bc-old.lua First part of rewrite 9 years ago
bc.lua Make oc-basecontrol more robust 9 years ago
lunit Add lunit suite 9 years ago
lunit-console.lua Add lunit suite 9 years ago
lunit.lua Add lunit suite 9 years ago
modem.lua Make oc-basecontrol more robust 9 years ago
serialization.lua First part of rewrite 9 years ago
test_bc.lua Make oc-basecontrol more robust 9 years ago

README.md

oc-basecontrol

oc-basecontrol is a OpenComputers generic base control library.

Documentation

Load oc-basecontrol into your application:

bc = require("bc"):init("<master-address>")

where <master-address> is the address of you networks master. The master is only required to download the base structure file.

The basic idea behind basecontrol is, that network node have a set of nouns, which represent different values. A computer near a reactor for example could have a noun called power-output. Network nodes also have verbs, actions that other nodes can perform. The reactor comuputer could have a shutdown verb for example.

The bc object has the following methods to interface with verbs and nouns:

-- Retrieve a noun from it's network node
val = bc:get_noun("<noun>")

-- Set a noun on the local machine
bc:set_noun("<noun>", value)

-- Call a verb on it's network node
bc:call_verb("<verb>", param)

-- Register a handler for verbs on the current machine
bc:on_verb("<verb>", function handler)

Additionally, there is

id = bc:listen_noun("<noun>", event_type, event_arg, function callback)

which is used to register asynchroneous callbacks on noun changes. event_type is one of

  • onchange => whenever the value changes, event_arg is ignored
  • onrising => whenever the value gets bigger, event_arg is ignored
  • onfalling => whenever the value gets smaller, event_arg is ignored
  • onvalue => whenever the value equals event_arg
  • onabove => whenever the value is bigger than event_arg
  • onbelow => whenever the value smaller than event_arg

A listener can be removed using

bc:listen_cancel("<noun>", id)

Testing

Testing is done using the "fake" backend and typing

$ ./lunit test_bc.lua