Difference between revisions of "Textutils.unserialize"

From ComputerCraft Wiki
Jump to: navigation, search
(Updated/Improved)
 
(One intermediate revision by one other user not shown)
Line 2: Line 2:
 
{{Function
 
{{Function
 
|name=textutils.unserialize
 
|name=textutils.unserialize
|args= [[string (type)|serialized]]
+
|args={{type|string}} serializedData
|returns=a copy of the original object that was serialized
+
|returns={{type|any}} unserializedData
 
|api=textutils
 
|api=textutils
 
|addon=ComputerCraft
 
|addon=ComputerCraft
|desc=Converts the serialized string back into an object. The string should have been created using [[Textutils.serialize|serialize]].   Note, the representation used by textutils actually creates Lua syntax, so that [loadstring] will also work to deserialize. See [[textutils.serialize]] for more information
+
|desc=Returns the data reassembled from string <var>serializedData</var>. Returns {{type|nil}} if unable to unserialize. Used mainly together with [[textutils.serialize]](). Also exists as textutils.unseriali'''s'''e under CC 1.6 or later.
 +
<br/>
 +
Note: the representation used by [[textutils.serialize]]() actually creates Lua-friendly syntax, so that [[loadstring]]() will also work to unserialize. See [[textutils.serialize]]() for more information.
 +
|examples=
 +
{{Example
 +
|desc=Unserializes a table and prints a value in it.
 +
|code=local serializedTable = "{value=2}"
 +
local myTable = '''textutils.unserialize( serializedTable )'''
 +
 +
[[print]]( myTable.value )
 +
|output=2
 +
}}
 
}}
 
}}
  
 
[[Category:API_Functions]]
 
[[Category:API_Functions]]

Latest revision as of 21:17, 16 February 2015


Grid Redstone.png  Function textutils.unserialize
Returns the data reassembled from string serializedData. Returns nil if unable to unserialize. Used mainly together with textutils.serialize(). Also exists as textutils.unserialise under CC 1.6 or later.


Note: the representation used by textutils.serialize() actually creates Lua-friendly syntax, so that loadstring() will also work to unserialize. See textutils.serialize() for more information.
Syntax textutils.unserialize(string serializedData)
Returns any unserializedData
Part of ComputerCraft
API textutils

Examples

Grid paper.png  Example
Unserializes a table and prints a value in it.
Code
local serializedTable = "{value=2}"
local myTable = textutils.unserialize( serializedTable )

print( myTable.value )
Output 2