-
-
Notifications
You must be signed in to change notification settings - Fork 386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sort lua components during serialization #6070
base: master
Are you sure you want to change the base?
Conversation
In the serialization of the Lua objects there is a system of "one definition", when all subsequent mention of the object only refer to it. It is vital that the full definition meets before the rest of the refs to the object, otherwise an error occurs. The same objects can now meet in different lua components, and this means that we must ensure the order of processing procedure during saving and loading. fixes pioneerspacesim#6064
So I looked again and now I saw some promise that the values inside the json object are sorted: Lines 11543 to 11546 in 89d503a
I wonder, can we trust this and not even use |
I like the explicit sort, just in case that library sorts things slightly differently than |
There is a strong guarantee that the contents of a JSON object are lexicographically sorted when written to and read from disk, and that sort order is based on the container type used in the The problem at hand is that we are potentially deserializing keys in a different order than we are serializing them, due to the instability of Lua table traversal. This requires a sorted order for keys when serializing, but as long as that sort is performed using Note that the data referred to by |
Indeed, very specifically written, thanks! But still, maybe we can count on the fact that these strings in a sense are still on the stack, because the table containing them is on the stack? Not that I am against |
That would be relying on undocumented behavior, and so I'd somewhat prefer to avoid doing so in the general case. In this particular case however, because strings are uniquely interned in the global Lua string table (not actually a Regardless of |
In the serialization of the Lua objects there is a system of "one definition", when all subsequent mention of the object only refer to it. It is vital that the full definition meets before the rest of the refs to the object, otherwise an error occurs.
The same objects can now meet in different lua components, and this means that we must ensure the order of processing procedure during saving and loading.
fixes #6064