Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
26 changes: 18 additions & 8 deletions library/lua/dfhack.lua
Original file line number Diff line number Diff line change
Expand Up @@ -845,16 +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_keyword(" ", "unit item plant building bld job workshop_job wsjob screen scr", "")
print_banner = false
end

Expand Down
Loading