From 7e01b004e9675fec417bee0eead7d3d0702395e6 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Fri, 4 May 2012 20:59:06 +0400 Subject: [PATCH] Implement timeouts in the core lua context, and quicksave script. --- LUA_API.rst | 20 ++++++ Lua API.html | 17 +++++ library/Core.cpp | 4 ++ library/LuaApi.cpp | 7 +- library/LuaTools.cpp | 129 +++++++++++++++++++++++++++++++++++++ library/PluginManager.cpp | 2 +- library/include/LuaTools.h | 2 + scripts/quicksave.lua | 28 ++++++++ 8 files changed, 207 insertions(+), 2 deletions(-) create mode 100644 scripts/quicksave.lua diff --git a/LUA_API.rst b/LUA_API.rst index d9488d60f..938664379 100644 --- a/LUA_API.rst +++ b/LUA_API.rst @@ -598,6 +598,14 @@ One notable difference is that these explicit wrappers allow argument count adjustment according to the usual lua rules, so trailing false/nil arguments can be omitted. +* ``dfhack.isWorldLoaded()`` + + Checks if the world is loaded. + +* ``dfhack.isMapLoaded()`` + + Checks if the world and map are loaded. + * ``dfhack.TranslateName(name[,in_english,only_last_name])`` Convert a language_name or only the last name part to string. @@ -950,6 +958,18 @@ Core context specific functions: Boolean value; *true* in the core context. +* ``dfhack.timeout(time,mode,callback)`` + + Arranges for the callback to be called once the specified + period of time passes. The ``mode`` argument specifies the + unit of time used, and may be one of ``'frames'`` (raw FPS), + ``'ticks'`` (unpaused FPS), ``'days'``, ``'months'``, + ``'years'`` (in-game time). All timers other than + ``'frames'`` are cancelled when the world is unloaded, + and cannot be queued until it is loaded again. + Returns the timer id, or *nil* if unsuccessful due to + world being unloaded. + * ``dfhack.onStateChange.foo = function(code)`` Event. Receives the same codes as plugin_onstatechange in C++. diff --git a/Lua API.html b/Lua API.html index 40706d14f..b96d12156 100644 --- a/Lua API.html +++ b/Lua API.html @@ -855,6 +855,12 @@ One notable difference is that these explicit wrappers allow argument count adjustment according to the usual lua rules, so trailing false/nil arguments can be omitted.