Your question is quite general, there are tons of ways of making a wire system, or something that acts like it. Details count as well.
Your script also includes input management but I can't tell what you really want by just reading it.
The only advice I can give is, generally, cables conveying power can be represented as a graph (general or grid-based), because it's all about connecting stuff to other stuff.
Then you must choose how it behaves when you switch power: does it traverses the network instantly? Does it have some propagation logic instead? Do you need execution order to prevent concurrent access or endless loops?
In Minecraft, redstone is updated on a grid as a mix of the two:
When a block changes state, it updates its neighbors instantly, which update too in one go, until it reaches some special blocks (repeaters, pistons, whatever) or runs out of power over the distance. These are put in a queue and are dequeued on the next tick, which starts again one more iteration etc until the queue is empty.
In another prototype I made, I handled power differently by representing it with a token that traverses a graph (nodes, grid, whatever). When power is 1, an "on" token is emitted and runs through the graph at each iteration (1 per frame or until it gets to the end). Same goes when power is 0, I send an "off" token. Then the token can change state during its course, like loosing power, increasing power, pick some information, split in two...
Lots of ways to do cables. One thing to avoid though: stack overflows and infinite loops :p