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

M1cr0API v4.0 (All in One Print, Redstone and File functions)

Started by M1cr0man, 25 March 2012 - 10:46 PM
M1cr0man #1
Posted 26 March 2012 - 12:46 AM
M1cr0API v4.0

Makin' it easier


18 functions to extend redstone and textutils APIs, ranging from redstone inverter, to monitor and terminal printer in one.

Links:
Spoiler-Latest API: [attachment=1114:M1cr0API v4.0.txt] Pastebin Link (Permanent): http://pastebin.com/YfV1CAHb
-Readme/Documentation: [attachment=1101:readme.txt]
Old Versions:
Spoiler-v3.2: [attachment=435:M1cr0API v3.2.txt]
-v3.1: [attachment=421:M1cr0API v3.1.txt]
-v3.0 for 1.31+: [attachment=392:M1cr0API v3.0.txt]
-v2.9 for 1.3+: [attachment=308:M1cr0API v2.9.txt]
-v2.8 for 1.3+: [attachment=298:M1cr0API v2.8.txt]
-v2.7 for 1.3+: [attachment=194:M1cr0API v2.7.txt]
-v2.6 for 1.3+: [attachment=148:M1cr0API v2.6.txt]

Included Functions:
Spoiler-Immibis' Serialize/Deserialize
-Anti-Ctrl+T
-Wait
-Bundled colour setter
-Rs & bundled checker
-Rs & bundled signaller
-Rs & bundled inverter
-Advanced read() with text centering, input limiting and monitor support
-Advanced print() with colour support, text centering and monitor support
-Save to file with auto-serialize
-Load from file with auto type conversion
-Wifi send with auto-serialize
-Wifi receive with auto type conversion]]–
-Advanced Print
-Word Wrap
-Peripheral side checker

-Usage instructions and descriptions can be found in the readme.txt

Usage:
Spoiler1. Download the API from above.
2. Rename it something handy. All functions you call must have '<filename>.' infront of them.
3. Copy it to the pc/floppy you are programming on OR
4. Copy it to %appdata%\.minecraft\mods\ComputerCraft\lua\rom\apis
5. ONLY for step 3, put 'os.loadAPI("<path>/<filename>")' at the start of your program.
6. Use '<filename>.<function>(<args>)' to call functions, or do shell.run("<filename>") and then <function>(<args>) to call functions.
7. Enjoy :D/>/>

Programs using M1cr0API:
Spoiler-M1cr0S Client and Server
-Nuclear Reactor Controller
-Post a link to your published programs that use this API and I will add them :)/>/>

Credits &amp; Licence:
Spoiler-Special Thanks to all those on the Computer Craft IRC, especially immibis for allowing me to
include and use his
serialize/deserialize functions.
LICENCE:
-You can use and redistribute the ORIGINAL API from this page in any program AS A FILE.
-You CANNOT redistribute a MODIFIED VERSION of this api.

Changelog:
Spoiler4.0:
*Set no longer needs all arguements defined
*tablesave is now save, and always serializes data.
*tableload is now load, and auto-converts any form of data to the right type. ie "true" will be converted to true. The filed does not need to have been saved with save()
*tablesend is now send. It automatically opens rednet modem, and always serializes data
*tablereceive is now receive. It automatically opens rednet modem, and converts data automatically to its correct type (see load())
+Printex now supports colours! Add %colour% to the text string to colour the text after it. add "bg" after the first % to set background color like so: %bggreen%
+Added comparetable. Compares all elements of a table and returns if they are exactly the same
+Passing events to os.pullEvent() should now work
-Removed comment from start of code
-History end position is no longer 1 line off
-Printex now sets next cursor line when "nocursor" isn't specified (like it should)
+Credit to everyone on #computercraft who helped me with problems I had with printex.
3.2:
-Fixed readex spamming the alternative character provided in arguement
3.1:
-Printex "history" and "hstmon" arguements now only prints the 2nd last string and older
-Mininmum redsig delay is now 0.1, due to how fast bundled cables update
-Fixed everything printed being wrote to history
3.0:
-Fixed possible problems with \n and tablesave/tableload
-Printex "nocursor" arguement actually restores the cursor to the original position now
+Documented wrap() command. See below for discription and usage
+Added "monitor", "omonitor", "hstmon" args to printex, check below for description and usage
2.9 (Major Changes):
-Fixed bug where redchk would return nil if no wire was present/broken on checked side
-Fixed wait returning the wrong event.
*Redchk and Redwait were doing the same thing. Removed redwait.
-Rewrote and Fixed most of the redstone functions firing when a different cable changes, and other bugs.
*Redsig now inverts the signal on a wire instead of setting it true and false (eg. It was not true in the first place)
2.8
-Printex now refreshes its screen size upon each call.
-Fixed readex line 285 error.
2.7:
-Fixed readex line 281 error
-Updated immibis' Serializer. Works properly with boolean false now.
-Remove a 0.1 wait from bundleset() which wasn't doing its purpose - stopping a timer from being set on if it is called at the same time as its tick.
+Added gethistory(agelimit) - will return printex history as a table. If <agelimit - number> is defined, it will only return that amount of recent history.
+Added 3 extra args to readex(). 3rd arg = Character/String to print on screen per key, 4th arg = Printex position/3rd arg, 5th arg = Printex 4th arg
2.6:
-Fixed nowrap argument making long strings with no \n not display.
-Fixed history argument not doing anything.
+Added "nocursor" argument - check readme for usage and description.
+Summarised printex code more. Slightly smaller file.
2.5:
+Initial Release

To-Do:
Spoiler-Add the API to cc-get.
-Any ideas?
Enjoy using my API, and remember to give credits :)/>/>
Also, post any bugs you find in comments
djblocksaway #2
Posted 06 April 2012 - 01:41 PM
nice API really useful :)/>/>
Noodle #3
Posted 06 April 2012 - 03:18 PM
At school right now. I WILL definately try when I get home.
sabian8 #4
Posted 06 April 2012 - 06:14 PM
I am a bit stuck with the anti-terminate function, how do i use it?
M1cr0man #5
Posted 06 April 2012 - 07:50 PM
I am a bit stuck with the anti-terminate function, how do i use it?
What you have to do is put <apifilename>.set(true, 1, 1) near the top of your program. The first argument is whether or not to enable anti-terminate (true, in your case). The other 2 arguments are for handling where the printex "history" argument starts and stops.
Hope this helps :)/>/>
M1cr0man #6
Posted 07 April 2012 - 02:16 PM
Added version 2.6. Changelog:
-Fixed printex nowrap argument making long strings with no n not display.
-Fixed printex history argument not doing anything.
+Added "nocursor" argument - check readme for usage and description.
+Summarised printex code more. Slightly smaller file.
cant_delete_account #7
Posted 08 April 2012 - 12:54 AM
Might wanna add some API docs, I have no idea what the names for the functions are, the arguments, etc.
M1cr0man #8
Posted 08 April 2012 - 11:38 PM
Might wanna add some API docs, I have no idea what the names for the functions are, the arguments, etc.
Check the readme.txt out. It contains all the functions, descriptions of what they do, their arguments and what they are/do aswell.
I might look into finding out how to add a help section to the CC-help command aswell.
sabian8 #9
Posted 09 April 2012 - 02:17 PM
I am a bit stuck with the anti-terminate function, how do i use it?
What you have to do is put <apifilename>.set(true, 1, 1) near the top of your program. The first argument is whether or not to enable anti-terminate (true, in your case). The other 2 arguments are for handling where the printex "history" argument starts and stops.
Hope this helps :P/>/>
Thanks! :D/>/>
M1cr0man #10
Posted 25 April 2012 - 09:50 PM
Added version 2.7 - Changelog:
-Fixed readex line 281 error
-Updated immibis' Serializer. Works properly with boolean false now.
-Remove a 0.1 wait from bundleset() which wasn't doing its purpose - stopping a timer from being set on if it is called at the same time as its tick.
+Added gethistory(agelimit) - will return printex history as a table. If <agelimit - number> is defined, it will only return that amount of recent history.
+Added 3 extra args to readex(). 3rd arg = Character/String to print on screen per key, 4th arg = Printex position/3rd arg, 5th arg = Printex 4th arg
Rwkeith #11
Posted 26 April 2012 - 04:22 AM
Very useful. Great contribution,
M1cr0man #12
Posted 20 May 2012 - 04:59 PM
I have stopped programming for a while now. My exams are coming in around 3 weeks time, and I have too much to do to be programming.

BUT after those 3 weeks, I will be actively updating this and some other programs I have ready to upload (But need to make videos), so don't think this API is dead for 1 second :P/>/>
M1cr0man #13
Posted 10 July 2012 - 11:27 PM
Major Changes in version 2.9:
-Fixed bug where redchk would return nil if no wire was present/broken on checked side
-Fixed wait returning the wrong event.
*Redchk and Redwait were doing the same thing. Removed redwait.
-Rewrote and Fixed most of the redstone functions firing when a different cable changes, and other bugs.
*Redsig now inverts the signal on a wire instead of setting it true and false (eg. It was not true in the first place)
-Removed comments at the start of the code, bringing it down to 360 lines.
M1cr0man #14
Posted 18 August 2012 - 04:53 PM
3.0 Is out. Printex finally has monitor support! :(/>/>
+Added "monitor", "omonitor", "hstmon" args to printex, check below for description and usage
+Documented wrap() command. See below for discription and usage
-Fixed possible problems with n and tablesave/tableload
-Printex "nocursor" arguement actually restores the cursor to the original position now
M1cr0man #15
Posted 18 August 2012 - 04:59 PM
Using M1cr0API in a published program? Post a link to it below and I will add it to the first post! :(/>/>
M1cr0man #16
Posted 31 August 2012 - 09:26 PM
3.1 released! Just bug fixes, but big ones:
-Printex "history" and "hstmon" arguements now only prints the 2nd last string and older
-Mininmum redsig delay is now 0.1, due to how fast bundled cables update
-Fixed everything printed being wrote to history
M1cr0man #17
Posted 06 September 2012 - 05:15 PM
3.2 is out. Only 1 simple but serious bugfix:
-Fixed readex spamming the alternative character provided in arguement

I'd appreciate any feedback anyone has on this. like if it made life easier when printing or working with bundled cables, or anything related, just post 'n' bump :D/>/>
M1cr0man #18
Posted 28 March 2013 - 05:35 AM
I'm back :)/> And I've made some HUGE additions, fixes, and changes - much needed colour support for printex being the largest one.

For now, here is the M1cr0API 4.0 Beta, I will release it next week or so as I want to do lots of testing on the changes I made. Changelog:
    *Set no longer needs all arguements defined
    *tablesave is now save, and always serializes data.
    *tableload is now load, and auto-converts any form of data to the right type. ie "true" will be converted to true. The filed does not need to have been saved with save()
    *tablesend is now send. It automatically opens rednet modem, and always serializes data
    *tablereceive is now receive. It automatically opens rednet modem, and converts data automatically to its correct type (see load())
    +Printex now supports colours! Add %colour% to the text string to colour the text after it. add "bg" after the first % to set background color like so: %bggreen%
    +Added comparetable. Compares all elements of a table and returns if they are exactly the same
    +Passing events to os.pullEvent() should now work
    -Removed comment from start of code
    -History end position is no longer 1 line off
    -Printex now sets next cursor line when "nocursor" isn't specified (like it should)
    +Credit to everyone on #computercraft who helped me with problems I had with printex.

Grab the readme from the first post, it is now updated. Please report any bugs you find here or directly to me on the irc.