replace more Core cpp code with calls to helpdb

also document devel/dump-rpc builtin
develop
myk002 2022-07-14 13:19:30 -07:00
parent 185f49976c
commit e926e1116e
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
5 changed files with 547 additions and 608 deletions

@ -255,6 +255,17 @@ type
----
``type command`` shows where ``command`` is implemented.
.. _devel/dump-rpc:
devel/dump-rpc
--------------
Writes RPC endpoint information to the specified file.
Usage::
devel/dump-rpc FILENAME
Other Commands
--------------
The following commands are *not* built-in, but offer similarly useful functions.

File diff suppressed because it is too large Load Diff

@ -148,6 +148,16 @@ void Lua::Push(lua_State *state, df::coord2d pos)
lua_setfield(state, -2, "y");
}
void GetVector(lua_State *state, std::vector<std::string> &pvec)
{
lua_pushnil(state); // first key
while (lua_next(state, 1) != 0)
{
pvec.push_back(lua_tostring(state, -1));
lua_pop(state, 1); // remove value, leave key
}
}
int Lua::PushPosXYZ(lua_State *state, df::coord pos)
{
if (!pos.isValid())

@ -339,6 +339,8 @@ namespace DFHack {namespace Lua {
}
}
DFHACK_EXPORT void GetVector(lua_State *state, std::vector<std::string> &pvec);
DFHACK_EXPORT int PushPosXYZ(lua_State *state, df::coord pos);
DFHACK_EXPORT int PushPosXY(lua_State *state, df::coord2d pos);

@ -250,6 +250,7 @@ local BUILTINS = {
alias='Configure helper aliases for other DFHack commands.',
cls='Clear the console screen.',
clear='Clear the console screen.',
['devel/dump-rpc']='Write RPC endpoint information to a file.',
die='Force DF to close immediately, without saving.',
enable='Enable a plugin or persistent script.',
disable='Disable a plugin or persistent script.',
@ -575,15 +576,26 @@ function search_entries(include, exclude)
ensure_db()
include = normalize_filter(include)
exclude = normalize_filter(exclude)
local commands = {}
for command in pairs(db) do
if (not include or matches(command, include)) and
(not exclude or not matches(command, exclude)) then
table.insert(commands, command)
local entries = {}
for entry in pairs(db) do
if (not include or matches(entry, include)) and
(not exclude or not matches(entry, exclude)) then
table.insert(entries, entry)
end
end
table.sort(commands, sort_by_basename)
return commands
table.sort(entries, sort_by_basename)
return entries
end
-- returns a list of all commands. used by Core's autocomplete functionality.
function get_commands()
local include = {types={ENTRY_TYPES.COMMAND}}
return search_entries(include)
end
function is_builtin(command)
ensure_db()
return db[command] and db[command].entry_types[ENTRY_TYPES.BUILTIN]
end
---------------------------------------------------------------------------
@ -633,7 +645,7 @@ function list_entries(skip_tags, include, exclude)
end
end
if #entries == 0 then
print('no entries found.')
print('No matches.')
end
end