- Name
-
SerializeTable -- serialize table to string (V9.0)
- Synopsis
-
s$ = SerializeTable(table[, t])
- Deprecated syntax
-
s$ = SerializeTable(table[, t])
- Function
-
This function serializes the table specified by
table
to a string and returns it.
The optional table argument t
can be used to specify additional options. The
following tags are currently recognized in the optional table argument:
Adapter:
-
The table will be serialized using the serializer that is specified in the
Adapter
tag. This can be the name of an external serializer plugin (e.g. xml
)
or it can be one of the following inbuilt serializers:
Default:
-
Use Hollywood's default serializer. This will serialize the table
to the JSON format. This is also the default if no other default has been
set using SetDefaultAdapter().
Inbuilt:
-
Use Hollywood's legacy serializer. This will serialize the table to
a custom, proprietary format.
UserTags:
-
This tag can be used to specify additional data that should be passed to serializer
plugins. If you use this tag, you must set it to a table of key-value pairs
that contain the additional data that should be passed to plugins. See User tags for details. (V10.0)
Mode:
-
This tag can be used to set the serialization mode to use for the operation. It
defaults to the serialization mode set using SetSerializeMode().
See SetSerializeMode for details. (V10.0)
Options:
-
This tag can be used to set the serialization options to use for the operation.
It defaults to the serialization options set using SetSerializeOptions().
See SetSerializeOptions for details. (V10.0)
SrcEncoding:
-
This tag can be used to specify the source character encoding. This defaults
to the string library's default character encoding as set by SetDefaultEncoding().
See SetDefaultEncoding for details. (V10.0)
DstEncoding:
-
This tag can be used to specify the destination character encoding. This defaults
to the string library's default character encoding as set by SetDefaultEncoding().
See SetDefaultEncoding for details. (V10.0)
If the Adapter
tag isn't specified, it will default to the default set
using SetDefaultAdapter().
The string can later be deserialized back to a table by using the
DeserializeTable() function. See DeserializeTable for details.
- Inputs
-
- table
- table to serialize
- t
- optional: table specifying further options (see above)
- Example
-
mytable = {1, 2, 3, 4, 5,
"Hello World",
x = 100, y = 150,
subtable = {10, 9, 8, 7}
}
s$ = SerializeTable(mytable)
mytable2 = DeserializeTable(s$)
The code above serializes mytable
to a string in the JSON format and then deserializes
that string back to a table. In the end, mytable
and mytable2
will be two independent
tables but with identical contents.