WriteTable(id, table[, t])
WriteTable(id, table[, txtmode, nobrk])
table
to the file
specified by id
. The table will be serialized using the serializer that
can be specified in the optional arguments. It will be written to the file
at the current cursor position which you can modify by using the Seek()
command. Tables written to files can later be loaded back into Hollywood tables
by using the ReadTable() command.
This function is fully recursive. Your table can contain as many subtables as you need. Additionally, the table can even contain Hollywood functions. See below for an example.
WriteTable()
supports several optional arguments. Before Hollywood 9.0, those
had to be passed as optional parameters (see above). Since Hollywood 9.0,
however, it is recommended to use the new syntax, which has a single optional
table argument that can be used to pass one or more optional arguments to
WriteTable()
.
The following table fields are recognized by this function:
Adapter:
xml
) or it can be one of the following inbuilt
serializers:
Default:
WriteTable()
will use the Inbuilt
serializer by default (see below). If you want
WriteTable()
to use the JSON serializer, you explicitly have to request
it by setting Adapter
to Default
.
Inbuilt:
WriteTable()
has used since
Hollywood 4.0 and for compatibility reasons, it is still the default
serializer. However, it is not recommended any longer as this serializer
will output data that is not in a human-readable format. Using the JSON
serializer is a much better choice.
If Adapter
isn't specified, it defaults to the default set using
SetDefaultAdapter(). Note that for compatibility reasons, this
default isn't Default
but Inbuilt
. See above for an explanation.
TextMode:
True
to tell WriteTable()
to export binary data
as text. Note that even if you set this tag to True
, the text won't be
in a human-readable format. If you want to serialize the table into
human-readable text, use the JSON serializer (see above). Defaults to
False
.
NoLineBreak:
TextMode
tag has been set to True
, WriteTable()
will automatically
insert line breaks after every 72 characters for better readability. If
you don't want that, set NoLineBreak
to True
. In that case, no line breaks
will be inserted. Note that this tag only affects Hollywood's legacy
serializer. It doesn't have any effect on other serializers. Defaults to False
. (V6.1)
UserTags:
Mode:
Options:
SrcEncoding:
DstEncoding:
mytable = {1, 2, 3, 4, 5, "Hello World", x = 100, y = 150, subtable = {10, 9, 8, 7}, mulfunc = Function(a, b) Return(a*b) EndFunction } OpenFile(1, "table.json", #MODE_WRITE) WriteTable(1, mytable, {Adapter = "default"}) CloseFile(1) OpenFile(1, "table.json", #MODE_READ) newtable = ReadTable(1, {Adapter = "default"}) CloseFile(1) Print(newtable[0], newtable[5], newtable.x, newtable.y, newtable.subtable[0], newtable.mulfunc(9, 9))The code above writes the table mytable to file "table.json". After that, it opens file "table.json" again and reads the table back into Hollywood. The imported table will be stored in the variable
newtable
. Finally, we
will access the newly imported table and print some of its data to the
screen. The output of the code above will be "1 Hello World 100 150 10 81".