Extended Table Module
Extended Table Module - table
Deep Copy a Table (table.deep_copy)
Declaration
copied_table = table.deep_copy(input_table)
Parameters and Return Values
- input_table
- table, the table to be copied
- copied_table
- table, the copy of the input table
Description
Recursively copies the input_table to create its duplicate. All values in the table, except for function and userdata, will be copied.
If the input table contains circular references, the reference relationships will also be copied.
Example
table.deep_copy
_g = table.deep_copy(_G)
Deep Print a Table (table.deep_print/stringify)
Declaration
table_text = table.deep_print(associated_table) -- Outputs to standard output
table_text = stringify(associated_table) -- Does not output to standard output, only returns a string
Parameters and Return Values
- associated_table
- table, the table to be printed as a string
- table_text
- string, the textual representation of the table’s tree structure
Description
Prints the tree structure of a table.
note
- The printed structure does not guarantee format compatibility and may vary between versions.
- The
table.deep_printfunction outputs content to theprintbuffer, whilestringifydoes not. - Non-table reference types (userdata, functions) cannot be deserialized using
table.load_string, and only human readability is guaranteed.
Example
table.deep_print
local s = table.deep_print(_G)
sys.alert(s)
Load a Table from a String (table.load_string)
Declaration
associated_table = table.load_string(table_text)
Parameters and Return Values
- table_text
- string, the textual representation of the table’s tree structure, which can only contain static data and no dynamic code
- associated_table
- table, returns the table structure if successful, or
nilif failed
- table, returns the table structure if successful, or
Description
Converts a textual tree structure description into a table object.
note
-
When there are no circular references or non-table reference types,
table.load_stringis the inverse function ofstringify. -
This function differs from
loadin that it does not execute code in the text and only uses static data. -
For example, the following example contains runtime code, resulting in
bbeingnil.b = table.load_string[[ {
a = os.execute('reboot'), -- This code will not execute and will return nil
} ]]
Example
table.load_string
local t = table.load_string[[ {
a = 1,
b = 2,
c = 3,
} ]]
sys.alert(t.b)