This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
HDeffo's profile picture

Feedback on redstone API (WIP not released)

Started by HDeffo, 01 April 2015 - 10:39 PM
HDeffo #1
Posted 02 April 2015 - 12:39 AM
Currently I am working on a redstone API integrating more logic controls into the existing system currently it will support two implementations of the code. I would appreciate if people could read code examples of both and tell me what they think of it so far and how I could improve the structure/make it easier if need be for end users.

the first usage is standard lua style functions
Spoilercircuit = redScript.solder() –#loads code
circuit.inputs = {"left","right","pseudo"} –#sets the inputs the code takes pseudo is a placeholder for code side
xorPart=circuit.xor(1,2) –#adds a xor logic part using inputs 1 and 2 (left and right)
–#xor will output high if it's two inputs are different
latchPart=circuit.latch(xorPart.output[1],3) –#creates a basic latch using the output of our xor and the pseudo input
–#this latch will lock it's output if the second input is high
circuit.output = "front" –#setting a single output for our redstone to go
circuit.run() –# starts the circuit running as a daemon(background)
sleep(3)
circuit.pseudo[1]=true –#makes pseudo input high
in this example redstone signal will output from the front if left and right inputs are different and continue this for 3 seconds after which it will lock whatever output it is currently sending.

The following code does the same thing but in a more advanced style using it's own scripting language built from lua.
Spoilercircuit = redScript.solder()
circuit.IO = {"left","right","front"}
circuit.script = "60(ab^Rc)"
circuit.run()

broken down:

60() means repeat for 3 seconds(60 ticks)

ab creates a table that functions similar to a stack pushing the values of a and b

^ pops the top two values in the current stack and pushes the xor value of the two

Rc pops the top value of the stacks and returns it to the IO defined after in this case c or "front"


Colored cables and analog will both be supported but for now I was just curious how people felt about the current structure I'm going with for this API
Edited on 02 April 2015 - 08:25 PM
HDeffo #2
Posted 02 April 2015 - 10:32 PM
Update: here is a full list of syntax for the scripting any feedback good or bad would be nice.

note this list isn't written in a good format yet until I finish the code behind it but this is just a quick compiled "idea" list

SYNTAX
===========================
( loop x ticks
{ loop x iterations
. end declaration
^ pop top two of stack and push XOR
R pop top stack and output value
> shift stack right one
< shift stack left one
D duplicates top of stack
P pop top stack
X swap top two values in stack
M moves value to top of stack
- inverts the top of the stack
&amp; pop top two of stack and push AND
| pop top two of stack and push OR
L pause for x ticks
[ set goto position
] jump to last [
? continues if top of stack is high and pops
: else condition to !
! stops circuit


examples of basic logic gates using the above syntax
NOT
a-Rc
OR
ab|Rc
NOR
ab|-Rc
AND
ab&amp;Rc
NAND
ab&amp;-Rc
XOR
ab^Rc
XNOR
ab^-Rc
IMPLY
a-b|Rc
Edited on 02 April 2015 - 08:33 PM