oc-basecontrol is a library for distributed base control systems in OpenComputers.
Find a file
Rahix b205779a29 Rewrite attempt 1
Signed-off-by: Rahix <rahix@rahix.de>
2019-04-17 12:42:02 +02:00
.gitignore Add gitignore 2017-04-10 16:55:59 +02:00
bc-tests.lua Rewrite attempt 1 2019-04-17 12:42:02 +02:00
bc.lua Rewrite attempt 1 2019-04-17 12:42:02 +02:00
component.lua Make testable version work in-game 2019-03-08 23:53:23 +01:00
event.lua Rewrite attempt 1 2019-04-17 12:42:02 +02:00
lunit Add lunit suite 2017-04-10 16:52:58 +02:00
lunit-console.lua Add lunit suite 2017-04-10 16:52:58 +02:00
lunit.lua Add lunit suite 2017-04-10 16:52:58 +02:00
network.lua Rewrite attempt 1 2019-04-17 12:42:02 +02:00
README.md Update README 2019-04-12 10:50:26 +02:00
scratch.lua Make testable version work in-game 2019-03-08 23:53:23 +01:00
serialization.lua First part of rewrite 2017-04-11 10:51:16 +02:00
uuid.lua Rewrite attempt 1 2019-04-17 12:42:02 +02:00

oc-basecontrol

oc-basecontrol is an OpenComputers generic base control library.

Documentation

Load oc-basecontrol into your application:

bc = require("bc"):init(<nouns>, <verbs>)

where <nouns> is a table containing all nouns (described later) and their initial value and <verbs> is a table containing all verbs and their callbacks.

The basic idea behind basecontrol is, that network nodes 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 computer 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)

Additionally, there is

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

which is used to register asynchroneous callbacks on (possibly remote) 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 a "fake" backend and typing

$ ./lunit test_bc.lua