Posted 19 October 2016 - 04:47 PM
I'm trying to port Brett Beauregard's Arduino PID library to Lua/ComputerCraft for controlling reactors/turbines/etc. The code appears pretty straightforward, and I have a mostly-complete implementation over at gist, but I'm having trouble figuring out how to connect the input, output, and setpoint variables.
The original library uses C++ pointers to allow Compute() and other methods to directly access the input, output, and setpoint; this saves the overhead of having additional methods such as GetOutput() or SetInput(). Of course, Lua doesn't have the concept of a pointer, and so a different approach is required. The obvious/naive solution would be to simply add SetInput() and its ilk, but I have a gut feeling that there's a more "Lua-ish" way to go about it.
As the experts, how would you recommend setting up these operating parameters, and is there anything I should change in my implementation to make it more ComputerCraft-friendly (as opposed to the vanilla Lua interpreter)?
The original library uses C++ pointers to allow Compute() and other methods to directly access the input, output, and setpoint; this saves the overhead of having additional methods such as GetOutput() or SetInput(). Of course, Lua doesn't have the concept of a pointer, and so a different approach is required. The obvious/naive solution would be to simply add SetInput() and its ilk, but I have a gut feeling that there's a more "Lua-ish" way to go about it.
As the experts, how would you recommend setting up these operating parameters, and is there anything I should change in my implementation to make it more ComputerCraft-friendly (as opposed to the vanilla Lua interpreter)?