This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
chiloxsan's profile picture

[1.3] textutils.unserialize doesn't return correctly

Started by chiloxsan, 02 September 2012 - 04:54 AM
chiloxsan #1
Posted 02 September 2012 - 06:54 AM
When unserializing a serialized table that has another serialized table with strings inside it, textutils.unserialize returns a string instead of the table it's meant to return.

To reproduce:
  1. Open an interactive lua prompt on a computer.
  2. Assign variable a to the output of textutils.serialize({"a", "b", "c"})
  3. Assign variable b to the output of textutils.serialize({"test", a})
  4. Now, assign variable c to the output of textutils.unserialize(b)
  5. Running type( c ) returns "string"
Noodle #2
Posted 02 September 2012 - 09:26 PM
Because you never unserialized the var c.. Serialize makes the whole table into a string.
EDIT: Now I see the problem, c = textutils.unserialize(:D/>/>
Could you post all the code?
chiloxsan #3
Posted 03 September 2012 - 07:05 AM
Because you never unserialized the var c.. Serialize makes the whole table into a string.
EDIT: Now I see the problem, c = textutils.unserialize( :D/>/>
Could you post all the code?
I first noticed an error in my tree network master where it would drop a packet where it can't unserialize it to find the destination. I do not think the problem is in my code, but in textutils.unserialize and textutils.serialize.

Let me explain. When you serialize table A {"a", "b", "c"} from above it turns into the string, which looks like this:

Example 1:
[indent=1]{[1]="a", [2]="b", [3]="c",}[/indent]

Now, when you try to serialize a table containing another string AND the serialized string of example 1, it looks like this:

Example 2:
[indent=1]{[1]="test", [2]="{[1]="a", [2]="b", [3]="c",}",}[/indent]

Now, I believe that textutils.unserialize gets "confused" when it encounters a serialized table with another serialized table with strings in side it (example 2), because the nested serialized string contains more quotation marks shortly after, so to textutils.unserialize table index 2 looks like this:

[indent=1][2]="{[1]="[/indent]

where it's meant to look like this:

[indent=1][2]="{[1]="a", [2]="b", [3]="c",}"[/indent]
Sebra #4
Posted 15 September 2012 - 09:59 AM
Seems fixed in 1.41.
chiloxsan #5
Posted 15 September 2012 - 10:28 AM
Seems fixed in 1.41.

Yep, it's fixed right after I replaced the default serialization with immibis' serialization in my programs.