Skip to content

Commit 81b7696

Browse files
committed
Updates query docs
1 parent 4edb935 commit 81b7696

1 file changed

Lines changed: 63 additions & 64 deletions

File tree

docs/devel/query.rst

Lines changed: 63 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ devel/query
33
===========
44

55
.. dfhack-tool::
6-
:summary: todo.
6+
:summary: Search/print data algorithmically.
77
:tags: dev inspection
88

99

10-
Query is a script useful for finding and reading values of data structure
11-
fields. Purposes will likely be exclusive to writing lua script code,
12-
possibly C++.
10+
Query is a useful script for finding and reading values of data structure
11+
fields. You can use it to explore data structures, list contents of known
12+
structures, and you could even integrate it into a script to simply print
13+
some data out for a player.
1314

1415
This script takes your data selection eg.{table,unit,item,tile,etc.} then
1516
recursively iterates through it, outputting names and values of what it finds.
@@ -21,12 +22,12 @@ selection and any search pattern specified.
2122
.. Note::
2223

2324
This is a recursive search function. The data structures are also recursive.
24-
So there are a few things that must be considered (in order):
25+
So there are a few things that the algorithm must consider while recursing (in order):
2526

2627
- Is the search depth too high? (Default: 7)
2728
- Is the data capable of being iterated, or does it only have a value?
2829
- How can the data be iterated?
29-
- Is the iteration count for the data too high? (Default: 257)
30+
- Is the iteration count for the data too high? (Default: 2048)
3031
- Does the user want to exclude the data's type?
3132
- Is the data recursively indexing (eg. A.B.C.A.*)?
3233
- Does the data match the search pattern?
@@ -45,70 +46,67 @@ selection and any search pattern specified.
4546

4647
Usage examples::
4748

48-
devel/query -unit -getfield id
49-
devel/query -unit -search STRENGTH
50-
devel/query -unit -search physical_attrs -maxdepth 2
51-
devel/query -tile -search dig
52-
devel/query -tile -search "occup.*carv"
53-
devel/query -table df -maxdepth 2
54-
devel/query -table df -maxdepth 2 -excludekinds s -excludetypes fsu -oneline
55-
devel/query -table df.profession -findvalue FISH
56-
devel/query -table df.global.ui.main -maxdepth 0
57-
devel/query -table df.global.ui.main -maxdepth 0 -oneline
58-
devel/query -table df.global.ui.main -maxdepth 0 -1
49+
devel/query --unit --getfield id
50+
devel/query --unit --search STRENGTH
51+
devel/query --unit --search physical_attrs -maxdepth 2
52+
devel/query --tile --search dig
53+
devel/query --tile --search "occup.*carv"
54+
devel/query --table df -maxdepth 2
55+
devel/query --table df -maxdepth 2 --excludekinds s --excludetypes fsu --oneline
56+
devel/query --table df.profession --findvalue FISH
57+
devel/query --table df.global.ui.main --maxdepth 0
58+
devel/query --table df.global.ui.main --maxdepth 0 --oneline
59+
devel/query --table df.global.ui.main --maxdepth 0 -1
5960

6061
**Selection options:**
6162

62-
``-tile``
63-
Selects the highlighted tile's block, and then
64-
uses the tile's local position to index the 2D data.
65-
66-
``-block``
67-
Selects the highlighted tile's block.
63+
``--table <identifier>``
64+
Selects the specified table.
6865

69-
``-unit``
70-
Selects the highlighted unit
66+
.. Note::
7167

72-
``-item``
73-
Selects the highlighted item.
68+
You must use dot notation to denote sub-tables.
69+
eg. ``df.global.world``
7470

75-
``-plant``
76-
Selects the highlighted plant.
71+
``--block``
72+
Selects the highlighted tile's block.
7773

78-
``-building``
74+
``--building``
7975
Selects the highlighted building.
8076

81-
``-job``
82-
Selects the highlighted job.
77+
``--item``
78+
Selects the highlighted item.
8379

84-
``-script <script name>``
85-
Selects the specified script (which must support being included with ``reqscript()``).
80+
``--job``
81+
Selects the highlighted job.
8682

87-
``-json <file>``
83+
``--json <file>``
8884
Loads the specified json file as a table to query.
8985

9086
.. Note::
9187

9288
The path starts at the DF root directory.
9389
eg. -json /hack/scripts/dwarf_profiles.json
9490

95-
``-table <identifier>``
96-
Selects the specified table (ie. 'value').
97-
98-
.. Note::
91+
``--plant``
92+
Selects the highlighted plant.
9993

100-
You must use dot notation to denote sub-tables.
101-
eg. ``df.global.world``
94+
``--script <script>``
95+
Selects the specified script (which must support being included with ``reqscript()``).
10296

103-
``-getfield <name>``
104-
Gets the specified field from the selection.
97+
``--tile``
98+
Selects the highlighted tile's block, and then
99+
uses the tile's local position to index the 2D data.
105100

106-
Must use in conjunction with one of the above selection
107-
options. Must use dot notation to denote sub-fields.
101+
``--unit``
102+
Selects the highlighted unit
108103

109104
**Query options:**
110105

111-
``-search <pattern>``
106+
``--getfield <field>``
107+
Gets the specified field from the selection.
108+
109+
``--search <pattern>``
112110
Searches the selection for field names with substrings
113111
matching the specified value.
114112

@@ -117,56 +115,57 @@ Usage examples::
117115
devel/query -table dfhack -search pattern
118116
devel/query -table dfhack -search [ pattern1 pattern2 ]
119117

120-
``-findvalue <value>``
118+
``--findvalue <value>``
121119
Searches the selection for field values matching the specified value.
122120

123-
``-maxdepth <value>``
121+
``--maxdepth <value>``
124122
Limits the field recursion depth (default: 7)
125123

126-
``-maxlength <value>``
127-
Limits the table sizes that will be walked (default: 257)
124+
``--maxlength <value>``
125+
Limits the table sizes that will be walked (default: 2048)
128126

129-
``-excludetypes [a|bfnstu0]``
127+
``--excludetypes [a|bfnstu0]``
130128
Excludes native Lua data types. Single letters correspond to (in order):
131129
All types listed here, Boolean, Function, Number, String, Table, Userdata, nil
132130

133-
``-excludekinds [a|bces]``
131+
``--excludekinds [a|bces]``
134132
Excludes DF data types. Single letters correspond to (in order):
135133
All types listed here, Bitfield-type, Class-type, Enum-type, Struct-type
136134

137-
``-dumb``
135+
``--dumb``
138136
Disables intelligent checking for recursive data
139-
structures (loops) and increases the ``-maxdepth`` to 25 if a
137+
structures (loops) and increases the ``--maxdepth`` to 25 if a
140138
value is not already present
141139

142140
**General options:**
143141

144-
``-showpaths``
142+
``--showpaths``
145143
Displays the full path of a field instead of indenting.
146144

147-
``-setvalue <value>``
145+
``--setvalue <value>``
148146
Attempts to set the values of any printed fields.
149147
Supported types: boolean, string, integer
150148

151-
``-oneline``, ``-1``
152-
Reduces output to one line, except with ``-debugdata``
149+
``--oneline``, ``-1``
150+
Reduces output to one line, except with ``--debugdata``.
151+
Most data is already using one line, but some types have additional information.
153152

154-
``-alignto <value>``
153+
``--alignto <value>``
155154
Specifies the alignment column.
156155

157-
``-nopointers``
156+
``--nopointers``
158157
Disables printing values which contain memory addresses.
159158

160-
``-disableprint``
159+
``--disableprint``
161160
Disables printing. Might be useful if you are debugging
162161
this script. Or to see if a query will crash (faster) but
163162
not sure what else you could use it for.
164163

165-
``-debug <value>``
164+
``--debug <value>``
166165
Enables debug log lines equal to or less than the value provided.
167166

168-
``-debugdata``
167+
``--debugdata``
169168
Enables debugging data. Prints type information under each field.
170169

171-
``-help``
170+
``--help``
172171
Prints this help information.

0 commit comments

Comments
 (0)