Skip to content

Commit d24e8f1

Browse files
authored
Merge pull request #5674 from SilasD/lua-interpreter-help
Lua interactive interpreter - list shortcut keywords in help banner
2 parents 21fef5f + 0bce84e commit d24e8f1

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

docs/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Template for new versions:
7373
## API
7474

7575
## Lua
76+
- The ``Lua interactive interpreter`` banner now documents keywords such as ``unit`` and ``item`` which reference the currently-selected object in the DF UI.
7677

7778
## Removed
7879

library/lua/dfhack.lua

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -845,16 +845,26 @@ function dfhack.interpreter(prompt,hfile,env)
845845
return nil, 'not interactive'
846846
end
847847

848-
print("Type quit to exit interactive lua interpreter.")
848+
local function print_keyword(pre, keyword, post)
849+
dfhack.color(COLOR_RESET)
850+
if pre ~= nil then dfhack.print(pre) end
851+
dfhack.color(COLOR_YELLOW)
852+
dfhack.print(keyword)
853+
dfhack.color(COLOR_RESET)
854+
if post ~= nil then print(post) end
855+
end
856+
print_keyword("Type ", "quit", " to exit interactive lua interpreter.")
849857

850858
if print_banner then
851-
print("Shortcuts:\n"..
852-
" '= foo' => '_1,_2,... = foo'\n"..
853-
" '! foo' => 'print(foo)'\n"..
854-
" '~ foo' => 'printall(foo)'\n"..
855-
" '^ foo' => 'printall_recurse(foo)'\n"..
856-
" '@ foo' => 'printall_ipairs(foo)'\n"..
857-
"All of these save the first result as '_'.")
859+
print("Shortcuts:")
860+
print_keyword(" '", "= foo", "' => '_1,_2,... = foo'")
861+
print_keyword(" '", "! foo", "' => 'print(foo)'")
862+
print_keyword(" '", "~ foo", "' => 'printall(foo)'")
863+
print_keyword(" '", "^ foo", "' => 'printall_recurse(foo)'")
864+
print_keyword(" '", "@ foo", "' => 'printall_ipairs(foo)'")
865+
print_keyword("All of these save the first result as '", "_", "'.")
866+
print("These keywords refer to the currently-selected object in the game:")
867+
print_keyword(" ", "unit item plant building bld job workshop_job wsjob screen scr", "")
858868
print_banner = false
859869
end
860870

0 commit comments

Comments
 (0)