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

[ALPHA][0.115A] Colligo - A small inclusive API

Started by LDShadowLord, 16 February 2014 - 05:55 PM
LDShadowLord #1
Posted 16 February 2014 - 06:55 PM
Project Colligo, also known as Colligo or Pcol, is an API being developed by myself on the ReccaToir server as a well-rounded API to fit all of my needs. As I previously utilised a multitude of API's I decided a change must be had and began the development of Colligo, an API suited for anything I desired.


For those who want to wing it and not read what it can do, feel free to look at the code here or download it on your HTTP enabled device with the following script!

"pastebin get NPR21i0G pcol"


To all who stayed, good on you. Open the spoiler below to view all of the available functions.

Functions

getVersion() - Returns a string with the version contained within it.

reset() - Clears the entire screen, sets the cursor to 1,1 and defaults the text colour to white.

isAdvanced() - Returns a true or false depending on the type of computer

aPrint(type(c,r,l),text) - Prints the defined text to the center,right or left of the screen

aWrite(type(c,r,l),text) - Writes the defined text to the center,right or left of the screen

erPrint(type,message) - Prints an error beginning with the pre-defined error header and prints the defined text.



The spoiler below contains the past THREE versions changelog, so as not to clutter.

Changelog

100a

added getVersion()

added cPrint()


105a

added erPrint()

added reset()


115a

Rewrote erPrint()

Added tables to feed erPrint()

localised all functions - getting conflicts

rewrote cPrint() as aPrint()

added aWrite()




License

I, LDShadowLord, give permission for anyone to use my API as long as it is kept in a separate file and is loaded as an API with "os.loadAPI" and that the copyright header in the API file is left intact.

Edited on 18 February 2014 - 06:50 PM
TechMasterGeneral #2
Posted 16 February 2014 - 09:06 PM
Nice!!
If it's stable I may ask to use this in my program
theoriginalbit #3
Posted 16 February 2014 - 09:15 PM
you should localise variables in all your functions. also you should use math.ceil not math.floor in your cPrint function. here is an example of localising functions, while fixing your cPrint too.


function cPrint(text)
  local cx, cy = term.getCursorPos()
  local w, h = term.getSize() --# its good to get it again, just incase they've moved to a monitor or something since initialising the API
  local newX = math.ceil((w-#text)/2)
  term.setCursorPos(newX, cy)
  print(text)
end

by making the above variables local it keeps them out of the global space which is persistent even once your program has finished, and potentially could cause problems for other scripts.

also your getVersion, there's no point putting the string in a variable to then return it, just return the string.
awsmazinggenius #4
Posted 16 February 2014 - 09:18 PM
also your getVersion, there's no point putting the string in a variable to then return it, just return the string.
There is also no point in even making a function, just make a variable called "version", like this:

--#API's File#--
...
version = "your version"
...
--#Program (API already loaded)#--
...
print(api-foo.version)
...
theoriginalbit #5
Posted 16 February 2014 - 09:21 PM
There is also no point in even making a function, just make a variable called "version", like this:
-code snip-
not completely true… getter approaches are very common and do (normally) have a lot of merit behind them
LDShadowLord #6
Posted 16 February 2014 - 09:49 PM
0.115 includes localised variables and some other updates. Luacrawler, as of this moment I don't want it being distributed with another program, sorry. I may amend this at a later date (I probably will) and allow distribution.
LDShadowLord #7
Posted 19 February 2014 - 07:17 PM
Updated to version 0.115A - License & Changelog added to the OP.