Difference between revisions of "Textutils.serialize"
From ComputerCraft Wiki
| Line 2: | Line 2: | ||
{{Function | {{Function | ||
|name=textutils.serialize | |name=textutils.serialize | ||
| − | |args= [[ | + | |args= [[Table|anything]] |
|returns=a string representing the object | |returns=a string representing the object | ||
|api=textutils | |api=textutils | ||
| Line 11: | Line 11: | ||
|desc=Sends a table over rednet, demonstrates object recovery | |desc=Sends a table over rednet, demonstrates object recovery | ||
|code=myThing={name="Test", n=2} | |code=myThing={name="Test", n=2} | ||
| − | sThing=textutils.serialize(myThing) | + | sThing=textutils.serialize(myThing) |
| − | [[rednet.send]](receiverID, sThing) | + | [[rednet.send]](receiverID, sThing) |
| − | myCopy=[[textutils.unserialize]](sThing) | + | myCopy=[[textutils.unserialize]](sThing) |
| − | print(myCopy.name) | + | print(myCopy.name) |
|output=Test | |output=Test | ||
}} | }} | ||
}} | }} | ||
Revision as of 16:02, 4 October 2012
| Converts the object to a string that can be saved or sent and then converted back into a copy of the object later, using unserialize. Nested structures are supported, but tables with circular graphs will be detected and raise an error. | |
| Syntax | textutils.serialize(anything) |
| Returns | a string representing the object |
| Part of | ComputerCraft |
| API | textutils |
Examples
| Sends a table over rednet, demonstrates object recovery | |
| Code |
myThing={name="Test", n=2}
sThing=textutils.serialize(myThing)
rednet.send(receiverID, sThing)
myCopy=textutils.unserialize(sThing)
print(myCopy.name)
|
| Output | Test |