From 7e6f7f9c801a5e2b84e6ba28a3fb2e0a0a48d30c Mon Sep 17 00:00:00 2001 From: SilasD Date: Sat, 29 Nov 2025 10:15:49 -0800 Subject: [PATCH 1/3] library/lua/dfhack.lua interactive interpreter banner: list shortcuts When the `lua` interactive interpreter is started, the help banner now lists the shortcuts (that is, variable names with special handling) already implemented in `library/lua/utils.lua` `df_shortcut_var()`. These keywords allow the interpreter to use the currently-selected object in the DF UI. They are currently undocumented, as far as I can tell. (The `lua` interpreter documentation does contain two hints in the Examples.) --- library/lua/dfhack.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/lua/dfhack.lua b/library/lua/dfhack.lua index 15910b46f1..24fb10e226 100644 --- a/library/lua/dfhack.lua +++ b/library/lua/dfhack.lua @@ -855,6 +855,8 @@ function dfhack.interpreter(prompt,hfile,env) " '^ foo' => 'printall_recurse(foo)'\n".. " '@ foo' => 'printall_ipairs(foo)'\n".. "All of these save the first result as '_'.") + print("These keywords refer to the currently-selected object in the game:") + print(" unit item plant building bld job workshop_job wsjob screen scr") print_banner = false end From bcb22b54de666f814b5587a7df4c3e03d025905f Mon Sep 17 00:00:00 2001 From: SilasD Date: Sat, 29 Nov 2025 17:20:06 -0800 Subject: [PATCH 2/3] update changelog (Is there a better way to word this?) --- docs/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index 91c50db23a..8cacfc9c56 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -67,6 +67,7 @@ Template for new versions: ## API ## Lua +- The ``Lua interactive interpreter`` banner now documents keywords such as ``unit`` and ``item`` which reference the currently-selected object in the DF UI. ## Removed From 0bce84e60caff072285f268122d2fe1a6e68b2b7 Mon Sep 17 00:00:00 2001 From: SilasD Date: Sun, 30 Nov 2025 09:47:50 -0800 Subject: [PATCH 3/3] library/lua/dfhack.lua interactive interpreter banner: highlight keywords When the interactive interpreter is started, highlight the various commands and keywords in yellow. This includes banner and the 'Type quit to exit interactive lua interpreter.' message. --- library/lua/dfhack.lua | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/library/lua/dfhack.lua b/library/lua/dfhack.lua index 24fb10e226..0dadc4fa9c 100644 --- a/library/lua/dfhack.lua +++ b/library/lua/dfhack.lua @@ -845,18 +845,26 @@ function dfhack.interpreter(prompt,hfile,env) return nil, 'not interactive' end - print("Type quit to exit interactive lua interpreter.") + local function print_keyword(pre, keyword, post) + dfhack.color(COLOR_RESET) + if pre ~= nil then dfhack.print(pre) end + dfhack.color(COLOR_YELLOW) + dfhack.print(keyword) + dfhack.color(COLOR_RESET) + if post ~= nil then print(post) end + end + print_keyword("Type ", "quit", " to exit interactive lua interpreter.") if print_banner then - print("Shortcuts:\n".. - " '= foo' => '_1,_2,... = foo'\n".. - " '! foo' => 'print(foo)'\n".. - " '~ foo' => 'printall(foo)'\n".. - " '^ foo' => 'printall_recurse(foo)'\n".. - " '@ foo' => 'printall_ipairs(foo)'\n".. - "All of these save the first result as '_'.") + print("Shortcuts:") + print_keyword(" '", "= foo", "' => '_1,_2,... = foo'") + print_keyword(" '", "! foo", "' => 'print(foo)'") + print_keyword(" '", "~ foo", "' => 'printall(foo)'") + print_keyword(" '", "^ foo", "' => 'printall_recurse(foo)'") + print_keyword(" '", "@ foo", "' => 'printall_ipairs(foo)'") + print_keyword("All of these save the first result as '", "_", "'.") print("These keywords refer to the currently-selected object in the game:") - print(" unit item plant building bld job workshop_job wsjob screen scr") + print_keyword(" ", "unit item plant building bld job workshop_job wsjob screen scr", "") print_banner = false end