diff options
author | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-07-24 05:55:19 +0000 |
---|---|---|
committer | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-07-24 05:55:19 +0000 |
commit | 496a1fc6bb248d48e8d4c9b6bf5c6f8b5360c673 (patch) | |
tree | fe1a97a59013ad288442dabf7c3648a06cbf8ce5 | |
parent | 0ce4685c4fe385d59c7abafc7ad8b1b5289b4f6e (diff) | |
download | crawl-ref-496a1fc6bb248d48e8d4c9b6bf5c6f8b5360c673.tar.gz crawl-ref-496a1fc6bb248d48e8d4c9b6bf5c6f8b5360c673.zip |
Added support for colon-prefixed Lua one-liners in .crawlrc, documented
Lua fragment syntax sketchily.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1923 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r-- | crawl-ref/docs/crawl_options.txt | 52 | ||||
-rw-r--r-- | crawl-ref/source/initfile.cc | 20 |
2 files changed, 65 insertions, 7 deletions
diff --git a/crawl-ref/docs/crawl_options.txt b/crawl-ref/docs/crawl_options.txt index f431b8f483..cb43035271 100644 --- a/crawl-ref/docs/crawl_options.txt +++ b/crawl-ref/docs/crawl_options.txt @@ -84,6 +84,8 @@ The contents of this text are: 6-c Unix background, use_fake_cursor +7- Inline Lua. + -------------------------------------------------------------------------------- There are three broad types of Crawl options: true/false values @@ -206,15 +208,17 @@ sound = <regex>:<path to sound file> 3- Lua files. ============== -Lua files are scripts which can provide existing commands with a new meaning -or even create new commands (to be used in macros). If you don't know a -specific reason not to include some or all lua files, you'll do best to just -include them all. +Lua files are scripts which can provide existing commands with a new +meaning or create new commands (to be used in macros). To use Lua +files, Crawl needs to be compiled with support for user Lua scripts. +You can if your Crawl has Lua support by hitting V in-game. The list +of features Crawl displays should include "Lua user scripts". + +Lua files are included using the lua_file option (one file per line): lua_file = <path/name.lua> -The currently available lua's are - base.lua -- needed for other lua scripts +The available stock Lua scripts are stash.lua -- annotates the stash file for better searching (Ctrl-F) Searching for 'Long blades' will also turn up all weapons with the long blade skill. Similarly, you can use 'altar', @@ -228,8 +232,11 @@ The currently available lua's are gearset.lua -- provides commands for switching of complete sets via macro New macroable functions: rememberkit, swapkit eat.lua -- prompts to eat chunks in inventory. + pickup.lua -- smarter autopickup. trapwalk.lua -- allows travel to cross certain traps if you have enough HP. +Also see section 7 on inline Lua fragments. + 4- Interface. ============== @@ -1371,3 +1378,36 @@ use_fake_cursor = false targeting screens instead of relying on the term to draw the cursor. Use this if your term cannot show a cursor over darkgrey/black squares. + + +7- Inline Lua +------------------ + +Lua code can be used directly in your init.txt/.crawlrc. You can use +Lua to selectively include parts of your init.txt (based on character +type, for instance) using this syntax: + +< Lua code > +or +< +Lua code +> +or +: Lua code till end of line + +Examples: + +# Print a welcome message +: crawl.mpr("Hello " .. you.name()) + +< +# Another welcome message +crawl.mpr("Hi there") +> + +# Controlling visibility of options: +: if you.race() == "Mummy" then +autopickup = $?+"/ +: else +autopickup = $?+"/!% +: end diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc index 95b2494c36..60ba59ea53 100644 --- a/crawl-ref/source/initfile.cc +++ b/crawl-ref/source/initfile.cc @@ -1152,6 +1152,23 @@ void game_options::read_options(InitLineInput &il, bool runscript) if ((str.empty() || str[0] == '#') && !inscriptcond && !inscriptblock) continue; + if (!inscriptcond && str[0] == ':') + { + // The init file is now forced into isconditional mode. + isconditional = true; + str = str.substr(1); + if (!str.empty() && runscript) + { + // If we're in the middle of an option block, close it. + if (luacond.length() && l_init) + { + luacond += "]] )\n"; + l_init = false; + } + luacond += str + "\n"; + } + continue; + } if (!inscriptcond && (str.find("L<") == 0 || str.find("<") == 0)) { // The init file is now forced into isconditional mode. @@ -1160,7 +1177,8 @@ void game_options::read_options(InitLineInput &il, bool runscript) str = str.substr( str.find("L<") == 0? 2 : 1 ); // Is this a one-liner? - if (!str.empty() && str[ str.length() - 1 ] == '>') { + if (!str.empty() && str[ str.length() - 1 ] == '>') + { inscriptcond = false; str = str.substr(0, str.length() - 1); } |