Jump to content




A small bug with textutils.serialize...


  • You cannot reply to this topic
7 replies to this topic

#1 ds84182

  • Members
  • 184 posts

Posted 24 March 2013 - 02:53 PM

Now, textutils.serialize protects itself from recursion, but if the same table is inside another table which is not a child of itself, it still errors.

Sounds confusing?

local t1 = {"lol"}
local t2 = {{t1},{t1}}
print(textutils.serialize(t2))
The above program WILL fail with "Cannot serialize table with recursive entries"!
And as you can see, it isn't recursive.
Thats because when the main serialization function (serializeImpl) serializes a table, it adds it to tTracking when it enters the table, but not when it exits.
Adding "tTracking[t] = nil" above "return result" would fix this.

#2 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 24 March 2013 - 03:09 PM

Why would you need to serialize a table with recursive entries?

#3 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 24 March 2013 - 03:10 PM

View PostSuicidalSTDz, on 24 March 2013 - 03:09 PM, said:

Why would you need to serialize a table with recursive entries?
The point he is trying to make is it is not recursive, it just has the reference to the same table twice, which textutils THINKS is recursive when it is not.

#4 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 24 March 2013 - 03:13 PM

Ah, I see now. Makes sense.

Off topic: I had the oddest dream where Lyqyd and Cloudy were flooding the forum with os's to get back at the clueless members...

#5 Cloudy

    Ex-Developer

  • Members
  • 2,543 posts

Posted 24 March 2013 - 03:32 PM

Don't give me ideas!

Anyway, serialize needs work. Considering adding a new method for serializing and handling old and new serialize formats in unserialize.

#6 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 24 March 2013 - 03:38 PM

There was a serialize function that worked with recursive tables someone made in the forum. It's really old, so it's probably deep down in the programs section :P
Just need to find a way to use it without breaking current serialization (maybe add a header or something?).

#7 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 24 March 2013 - 04:47 PM

View PostCloudy, on 24 March 2013 - 03:32 PM, said:

Don't give me ideas!
Hehe. I could see you doing it B)

On topic: I've never tried to do this with textutils so this won't ever be a problem with me :P

#8 luaanon

  • Members
  • 7 posts

Posted 30 March 2013 - 05:37 PM

You're probably thinking of immibis' [Api] Proper Serialization.

As posted, it has an off-by-one bug. In deserialize, "pos = pos + 1" needs to be "pos = pos + 2". Other than that, it passed all the quick-and-dirty tests I threw at it.

One potential pitfall though is that the serialization is not human-readable, so it is not 100% compatible with textutils.serialize. If textutils.serialize was replaced with it, any scripts that depend on the output being human-readable (tricks with loadstring, dofile, etc) would break. I doubt that many scripts rely on this behavior :shrug:





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users