From 3be53369f544187af7bb88b1ee284ab1348f32af Mon Sep 17 00:00:00 2001 From: Matthew Cline Date: Sun, 15 Nov 2009 04:05:31 -0800 Subject: luaterp (&^T): load files via terp_file option You can now specify Lua files to be loaded for use in the wizard Lua interpreter via "terp_file = file_path" in your init file. These files will be run in the context of dlua, as opposed to the clua context of files included with "lua_file = file_path". --- crawl-ref/docs/options_guide.txt | 7 +++++++ crawl-ref/source/initfile.cc | 9 ++++++++- crawl-ref/source/luaterp.cc | 17 +++++++++++++++++ crawl-ref/source/options.h | 3 ++- 4 files changed, 34 insertions(+), 2 deletions(-) (limited to 'crawl-ref') diff --git a/crawl-ref/docs/options_guide.txt b/crawl-ref/docs/options_guide.txt index 1128495065..c8d4667aab 100644 --- a/crawl-ref/docs/options_guide.txt +++ b/crawl-ref/docs/options_guide.txt @@ -382,6 +382,13 @@ The available stock Lua scripts are Also see section 7 on inline Lua fragments. +The wizard-mode Lua interpreter (&^T) will, the first time it's invoked, +load all of the files that are specified with the terp_file option: + +terp_file = + +The Lua in these files will have access to all of the Crawl Lua internals +(that is, will be run in the context of dlua, not clua). 4- Interface. ============== diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc index 69496fda15..41a3d66371 100644 --- a/crawl-ref/source/initfile.cc +++ b/crawl-ref/source/initfile.cc @@ -819,6 +819,7 @@ void game_options::reset_options() #ifdef WIZARD wiz_mode = WIZ_NO; + terp_files.clear(); #endif #ifdef USE_TILE @@ -1976,7 +1977,7 @@ void game_options::read_option_line(const std::string &str, bool runscript) && key != "autopickup_exceptions" && key != "stop_travel" && key != "sound" && key != "travel_stop_message" && key != "force_more_message" - && key != "drop_filter" && key != "lua_file" + && key != "drop_filter" && key != "lua_file" && key != "terp_file" && key != "note_items" && key != "autoinscribe" && key != "note_monsters" && key != "note_messages" && key.find("cset") != 0 && key != "dungeon" @@ -2148,6 +2149,12 @@ void game_options::read_option_line(const std::string &str, bool runscript) clua.execfile(field.c_str(), false, false); if (!clua.error.empty()) mprf(MSGCH_ERROR, "Lua error: %s", clua.error.c_str()); +#endif + } + else if (key == "terp_file" && runscript) + { +#ifdef WIZARD + terp_files.push_back(field); #endif } else if (key == "colour" || key == "color") diff --git a/crawl-ref/source/luaterp.cc b/crawl-ref/source/luaterp.cc index 38219c775c..745cfbc12c 100644 --- a/crawl-ref/source/luaterp.cc +++ b/crawl-ref/source/luaterp.cc @@ -19,6 +19,9 @@ #include "cio.h" #include "clua.h" #include "dlua.h" +#include "options.h" + +#ifdef WIZARD static int _incomplete(lua_State *ls, int status) { @@ -126,7 +129,21 @@ void run_clua_interpreter(lua_State *ls) lua_settop(ls, 0); // clear stack } +static bool _loaded_terp_files = false; + void debug_terp_dlua() { + if (!_loaded_terp_files) + { + for (unsigned int i = 0; i < Options.terp_files.size(); i++) + { + dlua.execfile(Options.terp_files[i].c_str(), false, false); + if (!dlua.error.empty()) + mprf(MSGCH_ERROR, "Lua error: %s", dlua.error.c_str()); + } + _loaded_terp_files = true; + } run_clua_interpreter(dlua); } + +#endif diff --git a/crawl-ref/source/options.h b/crawl-ref/source/options.h index 3abd9bc1e6..b344176e99 100644 --- a/crawl-ref/source/options.h +++ b/crawl-ref/source/options.h @@ -168,7 +168,8 @@ public: std::string pizza; #ifdef WIZARD - int wiz_mode; // yes, no, never in wiz mode to start + int wiz_mode; // no, never, start in wiz mode + std::vector terp_files; // Lua files to load for luaterp #endif // internal use only: -- cgit v1.2.3-54-g00ecf