Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5232e2b

Browse files
committed
add dfhack-config/scripts to default script paths
1 parent bf995a0 commit 5232e2b

5 files changed

Lines changed: 28 additions & 27 deletions

File tree

docs/Core.rst

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ DFHack commands can be implemented in any of three ways:
2121
same version of DFHack. They are less flexible than scripts,
2222
but used for complex or ongoing tasks because they run faster.
2323

24-
:scripts: are Ruby or Lua scripts stored in ``hack/scripts/``.
25-
Because they don't need to be compiled, scripts are
26-
more flexible about versions, and easier to distribute.
27-
Most third-party DFHack addons are scripts.
24+
:scripts: are Ruby or Lua scripts stored in ``hack/scripts/`` or other
25+
directories in the `script-paths`. Because they don't need to
26+
be compiled, scripts are more flexible about versions, and
27+
they are easier to distribute. Most third-party DFHack addons
28+
are scripts.
2829

2930
All tools distributed with DFHack are documented `here <tools>`.
3031

@@ -37,6 +38,8 @@ DFHack commands can be executed in a number of ways:
3738
#. Pressing a key combination set up with `keybinding`
3839
#. From one of several `init-files`, automatically
3940
#. Using `script` to run a batch of commands from a file
41+
#. From an in-game command launcher interface like `gui/launcher`, the
42+
`hotkeys` overlay widget, or `gui/quickcmd`.
4043

4144
The DFHack console
4245
------------------
@@ -144,7 +147,7 @@ save-specific init files in the save folders.
144147
DFHack looks for init files in three places each time they could be run:
145148

146149
#. The :file:`dfhack-config/init` subdirectory in the main DF directory
147-
#. :file:`data/save/{world}/raw`, where ``world`` is the current save, and
150+
#. :file:`data/save/{world}/raw`, where ``{world}`` is the current save, and
148151
#. :file:`data/save/{world}/raw/objects`
149152

150153
For each of those directories, all matching init files will be executed in
@@ -171,7 +174,7 @@ dfhack\*.init
171174
On startup, DFHack looks for files of the form ``dfhack*.init`` (where ``*`` is
172175
a placeholder for any string, including the empty string).
173176

174-
These files are best used for keybindings and enabling persistent plugins
177+
These files are best used for keybindings and enabling persistent tools
175178
which do not require a world to be loaded.
176179

177180

@@ -230,9 +233,10 @@ Script paths are folders that DFHack searches to find a script when a command is
230233
run. By default, the following folders are searched, in order (relative to the
231234
root DF folder):
232235

233-
1. :file:`data/save/{<region folder>}/raw/scripts` (only if a save is loaded)
234-
2. :file:`raw/scripts`
235-
3. :file:`hack/scripts`
236+
#. :file:`dfhack-config/scripts`
237+
#. :file:`data/save/{<region folder>}/raw/scripts` (only if a save is loaded)
238+
#. :file:`raw/scripts`
239+
#. :file:`hack/scripts`
236240

237241
For example, if ``teleport`` is run, these folders are searched in order for
238242
``teleport.lua`` or ``teleport.rb``, and the first matching file is run.

docs/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
3939

4040
## Misc Improvements
4141
- Scrollable widgets now react to mouse wheel events when the mouse is over the widget
42+
- the ``dfhack-config/scripts/`` folder is now searched for scripts by default
4243

4344
## Documentation
4445
- `overlay-dev-guide`: added troubleshooting tips and common development workflows

docs/dev/Lua API.rst

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2629,8 +2629,8 @@ and are only documented here for completeness:
26292629

26302630
Registers ``path`` as a `script path <script-paths>`.
26312631
If ``search_before`` is passed and ``true``, the path will be searched before
2632-
the default paths (e.g. ``raw/scripts``, ``hack/scripts``); otherwise, it will
2633-
be searched after.
2632+
the default paths (e.g. ``dfhack-config/scripts``, ``hack/scripts``); otherwise,
2633+
it will be searched after.
26342634

26352635
Returns ``true`` if successful or ``false`` otherwise (e.g. if the path does
26362636
not exist or has already been registered).
@@ -5466,11 +5466,11 @@ Scripts
54665466
:local:
54675467

54685468
Any files with the ``.lua`` extension placed into the :file:`hack/scripts` folder
5469-
are automatically made available as DFHack commands. The command corresponding to
5470-
a script is simply the script's filename, relative to the scripts folder, with
5471-
the extension omitted. For example:
5469+
(or any other folder in your `script-paths`) are automatically made available as
5470+
DFHack commands. The command corresponding to a script is simply the script's
5471+
filename, relative to the scripts folder, with the extension omitted. For example:
54725472

5473-
* :file:`hack/scripts/add-thought.lua` is invoked as ``add-thought``
5473+
* :file:`dfhack-config/scripts/startup.lua` is invoked as ``startup``
54745474
* :file:`hack/scripts/gui/teleport.lua` is invoked as ``gui/teleport``
54755475

54765476
.. note::
@@ -5487,12 +5487,6 @@ the extension omitted. For example:
54875487
a mod developer would want to run a script from the console, it should
54885488
not be placed in this folder)
54895489

5490-
Scripts can also be placed in other folders - by default, these include
5491-
:file:`raw/scripts` and :file:`data/save/{region}/raw/scripts`, but additional
5492-
folders can be added (for example, a copy of the
5493-
:source-scripts:`scripts repository <>` for local development). See
5494-
`script-paths` for more information on how to configure this behavior.
5495-
54965490
Scripts are read from disk when run for the first time, or if they have changed
54975491
since the last time they were run.
54985492

@@ -5520,7 +5514,7 @@ General script API
55205514

55215515
* ``dfhack.run_script(name[,args...])``
55225516

5523-
Run a Lua script in :file:`hack/scripts/`, as if it were started from the
5517+
Run a Lua script in your `script-paths`, as if it were started from the
55245518
DFHack command-line. The ``name`` argument should be the name of the script
55255519
without its extension, as it would be used on the command line.
55265520

@@ -5562,8 +5556,8 @@ Importing scripts
55625556

55635557
Loads a Lua script and returns its environment (i.e. a table of all global
55645558
functions and variables). This is similar to the built-in ``require()``, but
5565-
searches all script paths for the first matching ``name.lua`` file instead
5566-
of searching the Lua library paths (like ``hack/lua``).
5559+
searches all `script-paths` for the first matching ``name.lua`` file instead
5560+
of searching the Lua library paths (like ``hack/lua/``).
55675561

55685562
Most scripts can be made to support ``reqscript()`` without significant
55695563
changes (in contrast, ``require()`` requires the use of ``mkmodule()`` and

docs/guides/modding-guide.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ For scripts with the same name, the `order of precedence <script-paths>` will
6060
be:
6161

6262
1. ``own-scripts/``
63-
2. ``data/save/*/raw/scripts/``
64-
3. ``raw/scripts/``
65-
4. ``hack/scripts/``
63+
2. ``dfhack-config/scripts/``
64+
3. ``data/save/*/raw/scripts/``
65+
4. ``raw/scripts/``
66+
5. ``hack/scripts/``
6667

6768
The structure of the game
6869
-------------------------

library/Core.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ void Core::getScriptPaths(std::vector<std::string> *dest)
487487
string df_path = this->p->getPath();
488488
for (auto it = script_paths[0].begin(); it != script_paths[0].end(); ++it)
489489
dest->push_back(*it);
490+
dest->push_back(df_path + "/dfhack-config/scripts");
490491
if (df::global::world && isWorldLoaded()) {
491492
string save = World::ReadWorldFolder();
492493
if (save.size())

0 commit comments

Comments
 (0)