Module jls.util.tables
Provide table helper functions.
Functions
merge (target, source, keep) | Copies the value from the source table into the target. |
compare (oldTable, newTable) | Returns a table containing the differences between the two specified tables. |
patch (oldTable, diff) | Returns a table patched according to the specified differences. |
getPath (t, path, defaultValue[, separator]) | Returns the value at the specified path in the specified table. |
setPath (t, path, value[, separator]) | Sets the specified value at the specified path in the specified table. |
removePath (t, path[, separator]) | Removes the value at the specified path in the specified table. |
Functions
- merge (target, source, keep)
-
Copies the value from the source table into the target.
This is a deep copy, sub table are also merged.
Parameters:
- target table the table to copy.
- source table a modified table.
- keep boolean true to indicate that existing target value should be kept, default is false.
Returns:
-
table
the target table.
- compare (oldTable, newTable)
-
Returns a table containing the differences between the two specified tables.
The additions or modifications are availables, the same values are discarded
and the deleted values are listed in a specific table entry named "_deleted".
Parameters:
Returns:
-
table
the differences or nil if there is no such difference.
- patch (oldTable, diff)
-
Returns a table patched according to the specified differences.
Parameters:
Returns:
-
table
the differences or nil if there is no such difference.
- getPath (t, path, defaultValue[, separator])
-
Returns the value at the specified path in the specified table.
A path consists in table keys separated by slashes.
The key are considered as string, number or boolean. Table or userdata keys are not supported.
Parameters:
- t table a table.
- path string the path to look in the table.
- defaultValue the default value to return if there is no value for the path.
- separator string the path separator, default is /. (optional)
Returns:
-
the value
- setPath (t, path, value[, separator])
-
Sets the specified value at the specified path in the specified table.
Parameters:
- t table a table.
- path string the path to set in the table.
- value the value to set.
- separator string the path separator. (optional)
Returns:
-
the previous value.
- removePath (t, path[, separator])
-
Removes the value at the specified path in the specified table.
Parameters:
- t table a table.
- path string the path to remove in the table.
- separator string the path separator. (optional)
Returns:
-
the removed value.