So, I was trying to test my basic skillz of Lua by writing a computer API, which "helps you do common tasks when making computer programs".
The code itself is pretty simple, but just helps out some simple tasks and avoids typing long and cluttered commands.
Use of this API:
Spoiler
os.loadAPI("/pcapi")
local midx, midy = pcapi.middle()
local w, h = term.getSize() --# pcapi is not necesarry here
local title = "Welcome to CraftOS"
local background = "lightblue"
local welcometextln1 = "Welcome to CraftOS! Here you will have a tutorial about ComputerCraft Lua."
local welcometextln2 = "Click space to continue!"
pcapi.backCl(background, true)
pcapi.csPos((midx-#title)/2, 1)
write(title)
pcapi.csPos((midx-#welcometextln1)
-- And so on...
--[[
I can't give a normal example because of my lack
of imagination, but you get the point =)
]]--
Pastebin link for the API: http://www.pastebin.com/f1wL29PW
For lazy people out there:
pastebin get f1wL29PW pcapi
Sorry, the code is not commented, but it's simple, so you smart people will understand it =)I am currently working alone, would appreciate any and all help. I'd also like to learn more in Lua :)/>
Function list:
Spoiler
textCl(color)backCl(color, doclear)
per = wrapPer(optional side)
openRednet(optional side)
drawLine(color, startx, endx, height)
fillBox(color, widths, widthe, heights, heighte)
checkerBoard(fc, sc, widths, widthe, heights, heighte)
button = mkButton(color, text, tlx, brx, tly, bry)
boolean = checkIfClicked(button, clickx, clicky)
redraw(button, color, text)
button = removeButton(button, color)
middle()
csPos(x, y)
FAQ (Frequently Asked Questions):
Spoiler
Q: What functions does this API have?A: Open Function List spoiler.
Q: Why is this even useful?
A: It shortens the amount of code you would need to write to achieve the functionality of my functions.
Q: How long is this?
A: 435 lines.
Q: Where can I use this?
A: You can use this in your coding, but you can't make a post with this and claim that you made it. Also, if someone asks who made this API, refer to me.
Q: How often will you do updates?
A: I'll try to do updates as often as possible, but only when I'm not in school and in mood to code.
Q: asl :P/>
A: Information is in my profile, but only if you really need it. :)/>
Q: Will you do ComputerCraft videoz on the youtubez?
A: I do not have a computer powerful enough to create enjoyable videos.
If you ask a question, it might appear on the FAQ for your convenience :)/>
Spoiler
Version 1.2Spoiler
* Vastly improved error-checking* Buttons now support text!
+ Added redraw function, so you can change how the button looks at any time, also got rid of turnOnButton and turnOffButton functions, because they were pointless.
* Shrunk code - from 547 lines to 435 lines
+ Added version function, pointless really, but fun :)/>
+ Added writeTimes function - just like printTimes, but uses the write function
* Improved wrapPer and openRednet functions
Spoiler
+ Added local log2 function for color checking* Improved error-checking
* Changed drawLine(color, height) to drawLine(color, xstart, xend, height)
* Changed fillScreen(color, width, height) to drawBox(color, widths, widthe, heights, heighte)
+ Both textCl and backCl functions now support both strings and numbers (so you can use your favorite colors API if you want ;)/>)
* Improved button functions, so now you can choose the color you want to make the button and the color you want the button to be when it's on, still needs some work there
* Remove button function will also ask for colors!
* Improved clear function, now ENTIRELY clears the screen, including background color and text color resetting
- File expanded because of repetetive code