Module xbt.path
Submodule for paths.
The submodule path contains all operations for operating on paths in the XBT.
Info:
- Copyright: 2015, Matthias Hölzl
- License: MIT, see the file LICENSE.md.
- Author: Matthias Hölzl
Functions
new (id, ...) | Generate a new path starting at the root of the XBT. |
new_immutable (id, ...) | Generate a new immutable path starting at the root of the XBT. |
__eq (p1, p2) | Paths are compared using value equality. |
__tostring (p) | Convert a path to string |
down (p) | Descend one level deeper into the tree. |
right (p) | Move to the next sibling of the current node. |
up (p) | Move up one level in a tree. |
copy (p, extension) | Copy a path. |
root_path () | Return the root path for a path. |
is_path (p) | Check whether a value represents a path. |
Tables
meta | The metatable for path objects. |
Functions
- new (id, ...)
-
Generate a new path starting at the root of the XBT.
Parameters:
- id
The ID of the agent which is evaluating the XBT. If no
argument is provided for
id
, then a random UUID is generated, so that empty paths allocated without any arguments are never equal to each other. - ... Any number of positive integers can be passed as arguments to the function and will be used as the value for the result path.
Returns:
-
A new path.
- id
The ID of the agent which is evaluating the XBT. If no
argument is provided for
- new_immutable (id, ...)
-
Generate a new immutable path starting at the root of the XBT.
Parameters:
- id
The ID of the agent which is evaluating the XBT. If no
argument is provided for
id
, then a random UUID is generated, so that empty paths allocated without any arguments are never equal to each other. - ... Any number of positive integers can be passed as arguments to the function and will be used as the value for the result path.
Returns:
-
A new path.
- id
The ID of the agent which is evaluating the XBT. If no
argument is provided for
- __eq (p1, p2)
-
Paths are compared using value equality.
Parameters:
- p1 A path.
- p2 Another path.
Returns:
true
ifp1
andp2
point to the same location in the tree, false otherwise. Does not differentiate whether the paths differ in theirimmutable
flag. - __tostring (p)
-
Convert a path to string
Parameters:
- p A path.
Returns:
-
A string representation of
p
- down (p)
-
Descend one level deeper into the tree.
Parameters:
- p
A path pointing to a node
n
in an XBT.
Returns:
-
The value of
p
modified to point to the first child ofn
. - p
A path pointing to a node
- right (p)
-
Move to the next sibling of the current node.
Parameters:
- p
A path pointing to a node
n
in an XBT.
Returns:
-
The value of
p
modified to point to the right sibling ofn
. - p
A path pointing to a node
- up (p)
-
Move up one level in a tree.
Parameters:
- p
A path pointing to a non-root node
n
of an XBT.
Returns:
-
The value of
p
modified to point to the parent ofn
. - p
A path pointing to a non-root node
- copy (p, extension)
-
Copy a path.
Parameters:
- p A path pointing to a node in an XBT.
- extension
An extension of the path that will be added to the
copy. Either a positive integer for a single step or an array of
positive integers for a relative path. No extension is added if
extension
is falsy. Default isnil
.
Returns:
-
A copy of the path
p
. - root_path ()
-
Return the root path for a path.
When running the same XBT for multiple objects we use the first
component of the path as object id, so that we have a forest of
execution trees.
Returns:
-
A new path containing only the first element of the given
path.
- is_path (p)
-
Check whether a value represents a path.
Parameters:
- p The value to be tested.
Returns:
-
A Boolean indicating whether
p
is a path. This decision is made by checking whether the metatable ofp
is the one defined for paths, so path-like objects are not accepted.