Difference between revisions of "Textutils (API)"

From ComputerCraft Wiki
Jump to: navigation, search
m (Well, that wasn't exactly right either...)
(Addition of textutils.serializeJSON by CC 1.7.)
Line 27: Line 27:
  
 
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[textutils.serialize]]({{type|table}} table)</td>
 
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[textutils.serialize]]({{type|table}} table)</td>
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns a string representation of the table ''table'' for storage or transmission.</td></tr>
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns a string representation of the table ''table'' for storage or transmission. Also exists as textutils.seriali'''s'''e under CC 1.6 or later.</td></tr>
  
 
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[textutils.unserialize]]({{type|string}} text)</td>
 
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[textutils.unserialize]]({{type|string}} text)</td>
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns a table reassembled from string ''text''.</td></tr>
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns a table reassembled from string ''text''. Also exists as textutils.unseriali'''s'''e under CC 1.6 or later.</td></tr>
  
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[textutils.urlEncode]]({{type|string}} text)</td>
+
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[textutils.serializeJSON]]({{type|table}} table)</td>
 +
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns a JOSN-style representation of the table ''table'' for [[Commands (API)|command usage]]. Also exists as textutils.seriali'''s'''eJSON. Requires CC 1.7 or later.</td></tr>
 +
 
 +
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[textutils.urlEncode]]({{type|string}} text)</td>
 
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Makes a string safe to encode into a url. Spaces are replaced with +s. Unsafe characters such as '\', '£' and '}' are translated into ASCII code and preceded with a % for transmission. For reference visit: [http://www.blooberry.com/indexdot/html/topics/urlencoding.htm].</td></tr>
 
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Makes a string safe to encode into a url. Spaces are replaced with +s. Unsafe characters such as '\', '£' and '}' are translated into ASCII code and preceded with a % for transmission. For reference visit: [http://www.blooberry.com/indexdot/html/topics/urlencoding.htm].</td></tr>
 
</table>
 
</table>
  
 
[[Category:APIs]]
 
[[Category:APIs]]

Revision as of 12:09, 16 February 2015

The Textutils API is used to format and manipulate strings easily.

Grid disk.png   Textutils (API)

Method NameDescription
textutils.slowWrite(string text, number rate) Writes string text at current cursor position, character-by-character. Number argument rate is optional and is defaulted to 20. The higher the value of rate, the faster text is written (passing a value of 1 writes one character per second).
textutils.slowPrint(string text, number rate) Prints string text at current cursor position, character-by-character. Number argument rate is optional and is defaulted to 20. The higher the value of rate, the faster text is printed (passing a value of 1 prints one character per second). This function also prints a newline.
textutils.formatTime(number time, boolean TwentyFourHour) Takes input time and formats it in a more readable format. If second value is true, returns time in military time; if second value is false, returns time with AM or PM. Example: print(textutils.formatTime(os.time(), false))—os.time() returns MineCraft time.
textutils.tabulate(table table, table table2, ...) Prints tables in an ordered form. Each table is a row, the column width is auto-adjusted.
textutils.pagedTabulate(table table, table table2, ...) Prints tables in an ordered form, like textutils.tabulate. However, it waits for confirmation before scrolling down.
textutils.pagedPrint(string text [, number freeLines])Prints string text onto the screen, but waits for confirmation (after at least freeLines have been scrolled) before scrolling down further.
textutils.serialize(table table) Returns a string representation of the table table for storage or transmission. Also exists as textutils.serialise under CC 1.6 or later.
textutils.unserialize(string text) Returns a table reassembled from string text. Also exists as textutils.unserialise under CC 1.6 or later.
textutils.serializeJSON(table table) Returns a JOSN-style representation of the table table for command usage. Also exists as textutils.serialiseJSON. Requires CC 1.7 or later.
textutils.urlEncode(string text) Makes a string safe to encode into a url. Spaces are replaced with +s. Unsafe characters such as '\', '£' and '}' are translated into ASCII code and preceded with a % for transmission. For reference visit: [1].