Add a basic Lua console API

develop
lethosor 2017-12-07 14:43:27 -05:00
parent 622a8dacb6
commit 7721a142d8
4 changed files with 40 additions and 0 deletions

@ -36,6 +36,13 @@ Changelog
.. contents:: .. contents::
:depth: 2 :depth: 2
DFHack future
=============
Lua
---
- Added a new ``dfhack.console`` API
DFHack 0.43.05-r3 DFHack 0.43.05-r3
================= =================

@ -1966,6 +1966,18 @@ unless otherwise noted.
``listdir_recursive()`` returns the initial path and all components following it ``listdir_recursive()`` returns the initial path and all components following it
for each entry. for each entry.
Console API
-----------
* ``dfhack.console.clear()``
Clears the console; equivalent to the ``cls`` built-in command.
* ``dfhack.console.flush()``
Flushes all output to the console. This can be useful when printing text that
does not end in a newline but should still be displayed.
Internal API Internal API
------------ ------------

@ -53,6 +53,9 @@ Structures
- ``world`` fields formerly beginning with ``job_`` are now fields of - ``world`` fields formerly beginning with ``job_`` are now fields of
``world.jobs``, e.g. ``world.job_list`` is now ``world.jobs.list`` ``world.jobs``, e.g. ``world.job_list`` is now ``world.jobs.list``
API Changes
-----------
- Lua: Added a new ``dfhack.console`` API
DFHack 0.43.05-beta2 DFHack 0.43.05-beta2
==================== ====================

@ -2429,6 +2429,23 @@ static const luaL_Reg dfhack_designations_funcs[] = {
{NULL, NULL} {NULL, NULL}
}; };
/***** Console module *****/
namespace console {
void clear() {
Core::getInstance().getConsole().clear();
}
void flush() {
Core::getInstance().getConsole() << std::flush;
}
}
static const LuaWrapper::FunctionReg dfhack_console_module[] = {
WRAPM(console, clear),
WRAPM(console, flush),
{ NULL, NULL }
};
/***** Internal module *****/ /***** Internal module *****/
static void *checkaddr(lua_State *L, int idx, bool allow_null = false) static void *checkaddr(lua_State *L, int idx, bool allow_null = false)
@ -2964,5 +2981,6 @@ void OpenDFHackApi(lua_State *state)
OpenModule(state, "screen", dfhack_screen_module, dfhack_screen_funcs); OpenModule(state, "screen", dfhack_screen_module, dfhack_screen_funcs);
OpenModule(state, "filesystem", dfhack_filesystem_module, dfhack_filesystem_funcs); OpenModule(state, "filesystem", dfhack_filesystem_module, dfhack_filesystem_funcs);
OpenModule(state, "designations", dfhack_designations_module, dfhack_designations_funcs); OpenModule(state, "designations", dfhack_designations_module, dfhack_designations_funcs);
OpenModule(state, "console", dfhack_console_module);
OpenModule(state, "internal", dfhack_internal_module, dfhack_internal_funcs); OpenModule(state, "internal", dfhack_internal_module, dfhack_internal_funcs);
} }