TraversableTable
Traverse through tables like you’re using Instances!
This module allows you to use properties like Parent
to traverse through a table, no matter how complex.
Usage
local TraversableTable = require(path.to.TraversableTable)
local tbl = TraversableTable.new({
key = {
value = 8,
another = {
name = 'hi'
},
third = {
1,
2,
3
}
}
})
print(tbl.key.value.Parent:Get())
Docs
TraversableTable.new(tbl: Table|Dictionary) : Node
Create a new TraversableTable instance (a Node object)
Node[key] : Node
Just like using table[someKey]
, it will return the Node of the child element in the table
Node:Any(): { ForEach: function, Connect: function }
Allows you to apply a function to all children of the Node, or Connect a callback function to all RBXScriptSignal children of the Node.
Node:Construct() : Table|Dict
Constructs the Lua table from a Node and it’s children (like conversion from Nodes back to vanilla table form)
Node:Get() : any
Returns the raw value of the Node. Keep in mind, however, that if you change a Node’s value, any ancestor Nodes that are 2 or more levels up will not have updated raw values - this is why :Construct()
exists.
Node:List() : any
List all the keys of the children (more of a utility function tbh)
Node:Set(new: any) : any
Reconstruct the current Node to hold new
value instead. This will update its direct parent Node but nothing higher.
Links
Roblox Model: TraversableTable - Roblox
GitHub Repo: GitHub - R0bl0x10501050/TraversableTable
Closing
I know tables aren’t really meant for traversing, but in certain scenarios, this can be useful.
Hope you enjoy!