textutils.serialise
Converts value to a string representing it, which may be converted back to a value of the original type using textutils.unserialise.
|
|||
Prints a string representation of the given table. | |||
Code | <nowiki>
print(textutils.serialise({ 1, 2, foo = "bar", baz = { 1, 2, 3 } })
</nowiki>
|
||
Output | <nowiki>
{
1,
2,
baz = {
1,
2,
3,
},
foo = "bar"
}
</nowiki>
|
|
|||
Converts the given table to a string representing it, stores it in a file, then reads it back. | |||
Code | <nowiki>
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])
</nowiki>
|
||
Output | 1 1 |
textutils.serialise Function | |
---|---|
Syntax textutils.serialise(
| |
Returns | string |
API | textutils |
Source | CC:Tweaked (source) |
This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.