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

[APIs][Programs][Utilities]Mad's Programs

Started by Mads, 04 April 2012 - 06:21 AM
Mads #1
Posted 04 April 2012 - 08:21 AM
Mad's Programs

Index

____________________________________________________________________________________________________________________________________________________________________
____________________________________________________________________________________________________________________________________________________________________



[anchor='flib']fLib - Extended file handling

fLib is an API, that makes file handling a breeze. Write, append, even replace lines in a file with one line of code.
This is a must have for file-based programs. Also, this API can be used both inside CC, and outside.

Functions

flib.exists(path) --Returns true if path exists, and is a file
flib.getTable(path) --Returns a table with all the lines
flib.getLine(path, n) --Returns the Nth line
flib.getText(path) --Returns all the text in the file
flib.fwrite(path, text) --Writes text in a file
flib.fappend(path, text) --Appends text to a file
flib.fwriteAtStart(path, text) --Writes text at the start of a file
flib.fwriteFromTable(path, table) --Writes each field in table as a line in the file
flib.fappendFromTable(path, table) --Appends to a file with each field in table as a line
flib.fwriteAtStartFromTable(path, table) --Writes at the start of a file with each field in table as a line
flib.fwriteFromLine(path, n, text) --Writes text from Nth line, and keeps everything beneath the Nth line
flib.fwriteFromLineFromTable(path, line, table) --Writes from Nth line with each field in table> as a line, and keeps everything beneath the Nth line
flib.replaceLine(path, line, text) --Replaces the Nth line in a file with text
flib.getName(path) --Returns the name of the file, without the path
flib.getPath(path) --Returns the path of the file, without the name
flib.fremove(path) --Removes a file

Usage
You use this API as any other API. Install it, and you will be able to use every function like this:

flib.function(args)

Installation
  1. Download the file
  2. Navigate to your .minecraftmodsComputerCraftluarom folder
  3. put the file in the apis folder
  4. Start Minecraft
  5. Handle some files!

Download
You can download the API here



[anchor='ovar']Ovar - Persistant variables

This API makes storing variables something anyone can do. Create new variables, change them as you wan't to, save them and load them. Very useful for login systems and/or e.g. game highscores. It is very easy to use, and doesn't require much skill to master.


Functions

ovar.new(name, value) --Creates a new variable, that can now be loaded
ovar.load(name) --Returns an old value, asuming that it exists


Usage
Example 1: Creating a variable, and printing the value

local x = ovar.new("test", 10) --We create a the variable
x:save() --We save the value, so it can be used later
print(x.value) --We print the value
x:unload() --We unload the variable

------------------------------------------------
Output:
10


Example 2: Changing the value(Using the variable from before)

local x = ovar.load("test")
x.value = {"Hello ", "World!"} --We set the value of x to a table
x:save()
print(x.value[1] .. x.value[2]) --We print the two fields in the table

------------------------------------------------
Output:
Hello World!

Programs using this API
  1. Example login program by me

Installation
  1. Download the file
  2. Navigate to your .minecraftmodsComputerCraftluarom folder
  3. Put the file in the apis folder
  4. Start Minecraft
  5. Make some variables!

Download
You can download the API here




[anchor='mods']Modifications

[anchor='modbios1']Modified BIOS - os.remove() and custom read()

This BIOS adds one function, and replaces another one. It adds os.remove(), and replaces read() with a function I made.

Installation:
  1. Download the file
  2. Navigate to your .minecraftmodsComputerCraftlua folder
  3. Put the file in there
  4. Start Minecraft
  5. Read some text!

Download
You can download the BIOS here



[anchor='layout']Layout Classes/Modules

[anchor='layouttextfield']Textfield - Create editable textfields

This class allows you to create textfield, that can be edited, you can set the value, get the value, and all sorts of stuff. Useful for making GUIs.

Functions

Textfield.new(name, x, y) --Creates a new textfield at (x, y), and returns it
Textfield:draw() --Draws the textfield on the screen
Textfield:setText(text) --Sets the value teh the instance to text
Textfield:edit() --Puts the cursor inside the textfield, and lets you edit the text
Textfield:setVisible(:)/>/> --Will the the visiblility to b
Textfield:getText() --Returns the value
Textfield:getMaxLenght() --Returns the max lenght allowed
Textfield:isVisible() --Returns true if the instance is visible
Textfield:setMaxLenght(lenght) --Sets the max lenght to lenght
]Textfield:setX(x) --Sets the instance's x position to x
Textfield:setY(y) --Sets the instance's y position to y
Textfield:getX() --Returns the instance's x position
Textfield:getY() --Returns the instance's y position


Usage
This class is very simple to use.

Example 1: Creating a textfield, setting the value and drawing it

local tf = Textfield.new("tf", 10, 2, 30) --We create the textfield
tf:setText("Hello World!") --We set the text
tf:draw() --We draw the textfield

Example 2: Editing the textfield, and drawing it(Using the textfield from before)

tf:edit() --We go in edit mode
tf:draw() --When the user is done editing, we draw the textfield

You get the point. It is very simple, and right on.

Installation
  1. Download the file
  2. Navigate to your .minecraftmodsComputerCraftluarom folder
  3. Put the file in the apis folder
  4. Start Minecraft
  5. Make some textfields!

Download
You can download the API here



[anchor='layoutbutton']Button - Create clickable buttons

Functions

Button.new(name, x, y width, height) --Creates a new button, and returns it
Button:draw() --Draws the instance
Button:setText(text) --Sets the instance's text to text
Button:setVisible(:D/>/> --Will set the instance's visibility to b
Button:getText() --Returns the instance's text
Button:getWidth() --Returns the instance's width
Button:getHeight() --Returns the instance's height
Button:setAction(f) --Sets the action to f (MUST BE A FUNCTION)
Button:onClick() --Performs the instance's action
Button:setX(x) --Sets the instance's x position to x
Button:setY(y) --Sets the instance's y position to y
Button:getX() --Returns the instance's x position
Button:getY() --Returns the instance's y position
Button:getAction() --Returns the action
Button:setWidth(width) --Sets the instance's width to width
Button:setHeight(height) --Sets the instance's height to height


Usage
This class is very simple to use.

Example 1: Creating a button, setting the action, setting the text and drawing it

local f = function() --We create the action
	print("Hello World!")
end
local bu = Button.new("button1", 10, 2, 20, 5) --We make the button
bu:setAction(f) --We set the action
bu:setText("Click me!") --We set the text
bu:draw() --We draw the button


Example 2: Performing the action(Using the button from before)

bu:onClick()

Installation
  1. Download the file
  2. Navigate to your .minecraftmodsComputerCraftluarom folder
  3. put the file in the apis folder
  4. Start Minecraft
  5. Click some buttons!

Download
You can download the API here



[anchor='batch']Batch Interpreter - Write batch programs and run them
This is my current project, so I currently don't have anything to show. It's supposed to be done in about 3 weeks, maybe even after.
















If you make any programs/APIs/utilities using some of this software, please post them in the comments! That would mean alot to me!


If you read just some of this, thank you alot. Please leave suggestions/requests/feedback in the comments!
-mad1231999
Wolvan #2
Posted 04 April 2012 - 11:04 AM
Nice! Can you tell me a little bit more about the Custom BIOS? What is os.remove() used for example? Or what is the difference of read and custom read?
Mads #3
Posted 04 April 2012 - 11:11 AM
Nice! Can you tell me a little bit more about the Custom BIOS? What is os.remove() used for example? Or what is the difference of read and custom read?
os.remove() is an inbuilt function in Lua, that CC does not support. So I created it.
The read function has almost no difference, except the fact that my read function does not provide history compatiblity(Easy to add though)
And thanks!
Wolvan #4
Posted 04 April 2012 - 11:26 AM
offtopic:
I made the Tomoyo Banners. You can add yours to the signature
Mads #5
Posted 04 April 2012 - 12:50 PM
offtopic:
I made the Tomoyo Banners. You can add yours to the signature
Thanks! I certainly will
Mads #6
Posted 04 April 2012 - 12:51 PM
offtopic:
I made the Tomoyo Banners. You can add yours to the signature
I haven't got any PM:(
Wolvan #7
Posted 09 April 2012 - 11:07 PM
I wanted to ask if I could add your fLib API into 1 of my APIs

This is a secret bump
Mads #8
Posted 10 April 2012 - 01:26 PM
You can! Just give credit :P/>/>
Wolvan #9
Posted 10 April 2012 - 05:00 PM
OK I certainly will :D/>/>
And I didn't need to put your code in my file: I just looked at yours and used some elements of the file API :P/>/>
But thx anyway. If I need it someday I will credit you for sure
Zer0t3ch #10
Posted 10 April 2012 - 05:15 PM
All of these look AWESOME! I will most definitely be trying this later. These will definitely make a lot of things easier.

Also, would you be okay with me possibly implementing some of this INTO my code so that people don't have to download your APIs as well, provided I give you full credit for your work on the post and in the program? This is all theoretical right now, but please shoot me a PM and lemme know what you think.
Wolvan #11
Posted 10 April 2012 - 08:15 PM
I asked him that as well Zero :P/>/>
Mads #12
Posted 11 April 2012 - 04:34 PM
All of these look AWESOME! I will most definitely be trying this later. These will definitely make a lot of things easier.

Also, would you be okay with me possibly implementing some of this INTO my code so that people don't have to download your APIs as well, provided I give you full credit for your work on the post and in the program? This is all theoretical right now, but please shoot me a PM and lemme know what you think.
You can!
PixelToast #13
Posted 17 May 2012 - 07:43 PM
[indent=1]lol finnaly a batch inturpreter!, here i made yo a logo :3[/indent]
[indent=1]
EDIT: fixed lighting[/indent]
jojoxd #14
Posted 21 March 2013 - 12:06 PM
links are down :(/>
zekesonxx #15
Posted 21 March 2013 - 12:16 PM
Mad you screwed up Gitting something and deleted the repo. It needs to be fixed.
Mads #16
Posted 21 March 2013 - 08:07 PM
I made this repo in March 2012. It's all gone now :(/>
Dave-ee Jones #17
Posted 02 July 2013 - 04:14 AM
Can you fix it? Maybe put it on Pastebin instead of Github?
viluon #18
Posted 10 April 2014 - 09:21 AM
http://pastebin.com/6WYHCeeu
here ;)/>