Textutils API

From ComputerCraft
Jump to navigation Jump to search

Textutils.complete

Error creating thumbnail: Unable to save thumbnail to destination
Functiontextutils.formatTime
Formats time (in ticks) in a human-readable format such as "6:30 PM". If twentyFourHour is set to true, the AM/PM prefix is omitted, and the time is presented in a 24-hour format such as "18:30".
Syntax textutils.formatTime()
Returns string
Part of CC:Tweaked (source)
API textutils
Error creating thumbnail: Unable to save thumbnail to destination
ExampleWith 12-hour format
Prints the Minecraft world time in a 12-hour human-readable format.
Code
print(textutils.formatTime(os.time()))
Output Depends on the world time, for example "6:30 PM".
Error creating thumbnail: Unable to save thumbnail to destination
ExampleWith 24-hour format
Prints the Minecraft world time in a 24-hour human-readable format.
Code
print(textutils.formatTime(os.time(), true))
Output Depends on the world time, for example "18:30".

Textutils.pagedPrint Textutils.pagedTabulate

Error creating thumbnail: Unable to save thumbnail to destination
Functiontextutils.serialise
Converts value to a string representing it, which may be converted back to a value of the original type using textutils.unserialise.
Syntax textutils.serialise()
Returns string
Part of CC:Tweaked (source)
API textutils
Error creating thumbnail: Unable to save thumbnail to destination
ExampleSerialising a table
Prints a string representation of the given table.
Code
print(textutils.serialise({ 1, 2, foo = "bar", baz = { 1, 2, 3 } })
Output
{
  1,
  2,
  baz = {
    1,
    2,
    3,
  },
  foo = "bar"
}
Error creating thumbnail: Unable to save thumbnail to destination
ExampleSaving a table to a file
Converts the given table to a string representing it, stores it in a file, then reads it back.
Code
local t = { 1, 2, 3 }
print(t[1])
local f = fs.open("foo", "w")
f.write(textutils.serialise(t))
f.close()

local f = fs.open("foo", "r")
local t2 = textutils.unserialise(f.readAll())
f.close()
print(t2[1])
Output 1 1

Textutils.serialiseJSON

Error creating thumbnail: Unable to save thumbnail to destination
Functiontextutils.slowPrint
Slowly prints text, character-by-character, at the current cursor position in the current term. Accepts an optional rate parameter, in characters per second (default 20). This function is similar to textutils.slowWrite, however it automatically moves to the next line after writing.
Syntax textutils.slowPrint()
Returns nil
Part of CC:Tweaked (source)
API textutils
See also textutils.slowWrite
Error creating thumbnail: Unable to save thumbnail to destination
ExampleWith default rate
Slowly prints "Hello, world!" to the current term.
Code
textutils.slowPrint("Hello, world!")
Error creating thumbnail: Unable to save thumbnail to destination
ExampleWith custom rate
Slowly prints "Hello, world!" to the current term, at 5 characters per second.
Code
textutils.slowPrint("Hello, world!", 5)


Error creating thumbnail: Unable to save thumbnail to destination
Functiontextutils.slowWrite
Slowly writes text, character-by-character, at the current cursor position in the current term. Accepts an optional rate parameter, in characters per second (default 20). This function does not automatically move to the next line after writing.
Syntax textutils.slowWrite()
Returns nil
Part of CC:Tweaked (source)
API textutils
See also textutils.slowPrint
Error creating thumbnail: Unable to save thumbnail to destination
ExampleWith default rate
Slowly writes "Hello, world!" to the current term.
Code
textutils.slowWrite("Hello, world!")
Error creating thumbnail: Unable to save thumbnail to destination
ExampleWith custom rate
Slowly writes "Hello, world!" to the current term, at 5 characters per second.
Code
textutils.slowWrite("Hello, world!", 5)

Textutils.tabulate

Error creating thumbnail: Unable to save thumbnail to destination
Functiontextutils.unserialise
Converts a serialised string to a reassembled Lua value - the opposite of textutils.serialise. Returns nil if the unserialisation failed.
textutils.unserialise is implemented using load (source). It is loaded with an empty environment, therefore strings passed to textutils.unserialise cannot cause any harm to the computer. However, they can cause an infinite loop and cause the computer to crash for failing to yield!
Syntax textutils.unserialise()
Returns any
Part of CC:Tweaked (source)
API textutils
Error creating thumbnail: Unable to save thumbnail to destination
ExampleDeserialising a serialised table
Prints a value of the given serialised table.
Code
local serialised = "{ foo = \"bar\", fruit = \"apple\", colour = \"yellow\" }"
print(textutils.unserialise(serialised).fruit)
Output
apple

Textutils.urlEncode