From 7eb4fc19de542db0d3e271123f24773e0c8c481e Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Thu, 14 Jun 2012 12:46:12 +0400 Subject: [PATCH] Make dfhack.run_script usable from other scripts, and document it. --- LUA_API.rst | 12 ++++++++++++ Lua API.html | 10 ++++++++++ library/Core.cpp | 10 +++------- library/lua/dfhack.lua | 13 +++++++++---- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/LUA_API.rst b/LUA_API.rst index f40b786d2..2859f8678 100644 --- a/LUA_API.rst +++ b/LUA_API.rst @@ -491,6 +491,13 @@ Currently it defines the following features: Compares to coroutine.resume like dfhack.safecall vs pcall. +* ``dfhack.run_script(name[,args...])`` + + Run a lua script in hack/scripts/, as if it was started from dfhack command-line. + The ``name`` argument should be the name stem, as would be used on the command line. + Note that the script is re-read from the file every time it is called, and errors + are propagated to the caller. + * ``dfhack.with_suspend(f[,args...])`` Calls ``f`` with arguments after grabbing the DF core suspend lock. @@ -1148,6 +1155,11 @@ Internal API These functions are intended for the use by dfhack developers, and are only documented here for completeness: +* ``dfhack.internal.scripts`` + + The table used by ``dfhack.run_script()`` to give every script its own + global environment, persistent between calls to the script. + * ``dfhack.internal.getAddress(name)`` Returns the global address ``name``, or *nil*. diff --git a/Lua API.html b/Lua API.html index 5574c55b8..047457985 100644 --- a/Lua API.html +++ b/Lua API.html @@ -766,6 +766,12 @@ returning. Intended as a convenience function.

  • dfhack.saferesume(coroutine[,args...])

    Compares to coroutine.resume like dfhack.safecall vs pcall.

  • +
  • dfhack.run_script(name[,args...])

    +

    Run a lua script in hack/scripts/, as if it was started from dfhack command-line. +The name argument should be the name stem, as would be used on the command line. +Note that the script is re-read from the file every time it is called, and errors +are propagated to the caller.

    +
  • dfhack.with_suspend(f[,args...])

    Calls f with arguments after grabbing the DF core suspend lock. Suspending is necessary for accessing a consistent state of DF memory.

    @@ -1310,6 +1316,10 @@ Returns true, was_only_planned if removed; or false if none fo

    These functions are intended for the use by dfhack developers, and are only documented here for completeness: