The abilities with this API include:
The ability to add error codes to a temporary table
The ability to lookup error codes; If the lookup fails, the api has a failsafe.
The ability to remove error codes from the table, incase you ever want to.
The ability to natively parse errors with pcall
The functions are:
ecAPI.addCode(code, message)
ecAPI.lookupCode(code)
ecAPI.removeCode(code)
ecAPI.parseError(func)
An example of this is, say, you're on a server which you have a big computercraft network hooked up. The network gives you an error code, and you can easily look it up on the computer, or on a separate computer.
The api is made for easy use. Just have 1 lookup function, and all you have to do is, at the beginning of the code add your error codes.
For instance, if you want to add the error code "1" and have it say "Your program has crashed", all you have to do is put
ecAPI.addCode("1","Your program has crashed")
at the beginning of your program.An example program is:
Spoiler
local oldPull = os.pullEvent;
os.pullEvent = os.pullEventRaw;
os.loadAPI("ecAPI")
ecAPI.addCode("102", "Blank Ticket. Rewrite Ticket")
ecAPI.addCode("108", "Ticket File Exists, No Ticket Number Within. Rewrite Ticket")
term.clear()
term.setCursorPos(1,1)
term.setBackgroundColor(colors.white)
term.setTextColor(colors.cyan)
term.clear()
write("Error code: ")
code = read()
if code == "edit codes" then
shell.run("edit", "startup")
os.reboot()
else
ecAPI.lookupCode(code)
sleep(3)
os.reboot()
end
os.pullEvent = oldPull;
This program is from my train station I built as an experiment with random string generators (Don't ask…). I added error codes so that if something went wrong with the ticket inside the disk drive (Which I'm treating as the "ticket scanner") the computer would output an error. Then I could lookup the error, see what went on, and fix it easily.
You might think that since the API adds the codes to a table, once the computer is rebooted, the table will get removed. Well, at the beginning of every program, the computer re-inserts the code into the table. So it doesn't matter if the server get's restarted, or the computer get's shutdown, the codes will stay put. Plus, that means that no pesky temporary files are generated.
That's enough jabbering on my part, just download the api and use it for yourself!
pastebin: GT3JZBa6
pastebin get GT3JZBa6 ecapi
I really hope you all like it!