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

[1.6.5][SSP] textutils.unserialize can not handle lua keywords

Started by Abestanis, 05 January 2015 - 11:06 PM
Abestanis #1
Posted 06 January 2015 - 12:06 AM
VERSION:
1.6.5 for Minecraft 1.7.10

DESCRIPTION:
If you serialize a table containing a lua keyword as a key (e.g. repeat, do…), unserializing the returned string will fail silently and return nil.

EXPECTED RESULT:
textutils.unserialize should return the table given to textutils.serialize.

REPRODUCTION STEPS:
Type in the following code:

x = {}
x['repeat'] = 1
y = textutils.unserialize(textutils.serialize(x))
print(tostring(y))

SCREENSHOT:


Lignum #2
Posted 09 January 2015 - 07:16 PM
If I recall correctly, textutils.unserialise is pretty much just loadstring(). So you can imagine why this isn't working…
A possible fix would be to make textutils.serialise output ["do"] = 1 instead of do = 1 as shown in your screenshot.
Abestanis #3
Posted 09 January 2015 - 09:15 PM
I've tested it and it is possible to get it to work by wrapping the keyword in square brackets and quotes.
I think it would be simple to implement a check in textutils.serialize for the keywords and then add the square brackets and quotes.

dan200 #4
Posted 02 February 2015 - 09:27 PM
Fixed in CC1.66