|
|
7 years ago | |
|---|---|---|
| .gitignore | 9 years ago | |
| README.md | 7 years ago | |
| bc-tests.lua | 7 years ago | |
| bc.lua | 7 years ago | |
| component.lua | 7 years ago | |
| event.lua | 7 years ago | |
| lunit | 9 years ago | |
| lunit-console.lua | 9 years ago | |
| lunit.lua | 9 years ago | |
| network.lua | 7 years ago | |
| scratch.lua | 7 years ago | |
| serialization.lua | 9 years ago | |
| uuid.lua | 7 years ago | |
README.md
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_argis ignoredonrising=> whenever the value gets bigger,event_argis ignoredonfalling=> whenever the value gets smaller,event_argis ignoredonvalue=> whenever the value equalsevent_argonabove=> whenever the value is bigger thanevent_argonbelow=> whenever the value smaller thanevent_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