Jump to content




SerializeRec - Recursive Table Serialize - Compatible with textutils.unserialize(). v1

api

8 replies to this topic

#1 Wojbie

  • Members
  • 631 posts
  • LocationKinda lost

Posted 19 October 2015 - 10:51 AM

SerializeRec - Recursive Table Serialize - Compatible with textutils.unserialize(). v1.0

Have you ever needed to store a table with recursive entries? Did standard textutils.serialize() failed you? Then this api is for you!

SerializeRec is simple one function api that allows you to serialize tables that contain recursive entries. It preserves the structure of input table and outputs string that can be unserialized using standard cc textutils.unserialize back into said table with the same structure and correct everything.

Download Here: http://pastebin.com/APF0HTE0
Or ingame by using command:
pastebin get APF0HTE0 serializerec
(requires http-api to be active)

As it is api you need to os.loadAPI("serializerec") it. It contains one function in both spelling versions serialiseRec/serializeRec. You treat it like normal serialize and it will output string like normal serialize.

Features List:
  • Serializes recursive tables
  • Textutils.unserialize compatible
  • Awesome!
Example:
Spoiler


Change-log:
Spoiler

Plans For Future:
Spoiler

Any Comment and Suggestions how to improve Code are appreciated.

Edited by Wojbie, 16 January 2016 - 07:18 PM.


#2 Konlab

  • Members
  • 594 posts
  • LocationKerbin

Posted 19 October 2015 - 01:42 PM

Sounds very interesting and useful for example for saving the _G variable (containing _G).
Can this handle non-recursive tables in tables? And recursive tables pointing to grandparent? (E.g. a.b.c = a or a.b = _G)
On feature list Avesome should be Awesome

#3 Wojbie

  • Members
  • 631 posts
  • LocationKinda lost

Posted 19 October 2015 - 01:50 PM

View PostKonlab, on 19 October 2015 - 01:42 PM, said:

Can this handle non-recursive tables in tables? And recursive tables pointing to grandparent? (E.g. a.b.c = a
Yes it handles that!

View PostKonlab, on 19 October 2015 - 01:42 PM, said:

or a.b = _G)
But this will error cause _G contains functions and functions are not serialisable.

Basically it makes internal list of tables and when it encounters same table again it just notes that its same tale.
I am currently thinking of ways to shorten the output string cause when compared with standard one its longer and less readable.

Edited by wojbie, 19 October 2015 - 01:54 PM.


#4 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 19 October 2015 - 01:56 PM

You can string dump functions.

#5 Wojbie

  • Members
  • 631 posts
  • LocationKinda lost

Posted 19 October 2015 - 02:00 PM

View PostCreator, on 19 October 2015 - 01:56 PM, said:

You can string dump functions.

True but only functions that are lua based and don't contain upvalues. And then you hit string bug when attempting to save/transmit resulting string.

Edited by wojbie, 19 October 2015 - 02:08 PM.


#6 FUNCTION MAN!

  • Members
  • 292 posts

Posted 19 October 2015 - 10:20 PM

Base64 the functions.

#7 Wojbie

  • Members
  • 631 posts
  • LocationKinda lost

Posted 19 October 2015 - 10:49 PM

View PostDemHydraz, on 19 October 2015 - 10:20 PM, said:

Base64 the functions.
True that would work. Only problem left is that you don't have access to _G inside textutils.unserialise(). So there is no way to load() the string dump back into function. And making custom one that lets the string to unserialise access to _G would open hole that would allow for remote code execution. So while i agree its doable i simply don't see the usefulness of that.

#8 apemanzilla

  • Members
  • 1,421 posts

Posted 19 October 2015 - 10:55 PM

Also I don't think there will be a way to load dumped functions once CC updates to Lua 5.2 given that Dan's compatibility layer only allows text chunks, not binary chunks.

#9 FUNCTION MAN!

  • Members
  • 292 posts

Posted 19 October 2015 - 10:59 PM

The binary chunk thing only doesn't work if it's explicit, look:

Posted Image

edit: that is in game, I just cropped the screenshot so it isn't huge.

more edit: relevant lines

Edited by DemHydraz, 19 October 2015 - 11:03 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users