diff options
author | j-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-02-27 13:03:56 +0000 |
---|---|---|
committer | j-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-02-27 13:03:56 +0000 |
commit | 02294f67e4fc78d79d639d4c29aa72e22f93b06c (patch) | |
tree | 31a170cb7933750ed8b64cf8fd72dff373005ad7 /crawl-ref/source/clua.cc | |
parent | 7baa5392145a253c8f4744e12e90770c6147bd74 (diff) | |
download | crawl-ref-02294f67e4fc78d79d639d4c29aa72e22f93b06c.tar.gz crawl-ref-02294f67e4fc78d79d639d4c29aa72e22f93b06c.zip |
Apply Paul's patch 1901939: including files in init.txt
with some clean-up and fix in acr.cc to make the results
apply at once (instead of only after a screen redraw).
I've tested it and everything works fine. Recursive
inclusion, e.g. read_options('init.txt'), prints a stack
overflow error but doesn't crash the game, so I think
that's fine for now.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@3469 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/clua.cc')
-rw-r--r-- | crawl-ref/source/clua.cc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/crawl-ref/source/clua.cc b/crawl-ref/source/clua.cc index be10393602..85fca69605 100644 --- a/crawl-ref/source/clua.cc +++ b/crawl-ref/source/clua.cc @@ -1774,6 +1774,27 @@ static int crawl_setopt(lua_State *ls) return (0); } +static int crawl_read_options(lua_State *ls) +{ + if (!lua_isstring(ls, 1)) + return (0); + + const char* filename = lua_tostring(ls, 1); + FILE* f = fopen( filename, "r" ); + if (f) + { + FileLineInput fl(f); + Options.read_options(fl, true); + fclose(f); + } + else + { + mprf(MSGCH_WARN, "Warning: could not read options file '%s'", filename); + } + + return (0); +} + static int crawl_bindkey(lua_State *ls) { const char *s = NULL; @@ -2008,6 +2029,7 @@ static const struct luaL_reg crawl_lib[] = { "runmacro", crawl_runmacro }, { "bindkey", crawl_bindkey }, { "setopt", crawl_setopt }, + { "read_options", crawl_read_options }, { "msgch_num", crawl_msgch_num }, { "msgch_name", crawl_msgch_name }, |