diff --git a/NEWS.rst b/NEWS.rst index e55ca92c5..673ae31f9 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -36,6 +36,13 @@ Changelog .. contents:: :depth: 2 +DFHack future +============= + +Lua +--- +- Added a new ``dfhack.console`` API + DFHack 0.43.05-r3 ================= diff --git a/docs/Lua API.rst b/docs/Lua API.rst index 66c2a5a07..a6a2ab8cd 100644 --- a/docs/Lua API.rst +++ b/docs/Lua API.rst @@ -1966,6 +1966,18 @@ unless otherwise noted. ``listdir_recursive()`` returns the initial path and all components following it 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 ------------ diff --git a/docs/NEWS-dev.rst b/docs/NEWS-dev.rst index 2f0c3ea97..8dfe2866b 100644 --- a/docs/NEWS-dev.rst +++ b/docs/NEWS-dev.rst @@ -53,6 +53,9 @@ Structures - ``world`` fields formerly beginning with ``job_`` are now fields of ``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 ==================== diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index 39b4b41cb..0bf19e93e 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -2429,6 +2429,23 @@ static const luaL_Reg dfhack_designations_funcs[] = { {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 *****/ 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, "filesystem", dfhack_filesystem_module, dfhack_filesystem_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); }