summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/clua.cc
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-06-25 19:54:59 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-06-25 19:54:59 +0000
commit7ce53143a6ea781bb9bd2eb29995c6d160331328 (patch)
tree3a9aa283080572b5cc8fbb0eb9f30a8cdb55e465 /crawl-ref/source/clua.cc
parent648c698c072f989a8e351efbac07a0c9afb9b638 (diff)
downloadcrawl-ref-7ce53143a6ea781bb9bd2eb29995c6d160331328.tar.gz
crawl-ref-7ce53143a6ea781bb9bd2eb29995c6d160331328.zip
.des files can use a global Lua prelude (before maps are defined) that runs
at start of game, before any maps are loaded, and does not run in the context of any specific map. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1654 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/clua.cc')
-rw-r--r--crawl-ref/source/clua.cc22
1 files changed, 13 insertions, 9 deletions
diff --git a/crawl-ref/source/clua.cc b/crawl-ref/source/clua.cc
index 63f901f051..8ea71c26e4 100644
--- a/crawl-ref/source/clua.cc
+++ b/crawl-ref/source/clua.cc
@@ -532,18 +532,22 @@ bool CLua::callfn(const char *fn, int nargs, int nret)
lua_State *ls = state();
if (!ls)
return (false);
-
- lua_getglobal(ls, fn);
- if (!lua_isfunction(ls, -1))
+
+ // If a function is not provided on the stack, get the named function.
+ if (fn)
{
- lua_settop(ls, -nargs - 2);
- return (false);
+ lua_getglobal(ls, fn);
+ if (!lua_isfunction(ls, -1))
+ {
+ lua_settop(ls, -nargs - 2);
+ return (false);
+ }
+
+ // Slide the function in front of its args and call it.
+ if (nargs)
+ lua_insert(ls, -nargs - 1);
}
- // Slide the function in front of its args and call it.
- if (nargs)
- lua_insert(ls, -nargs - 1);
-
lua_call_throttle strangler(this);
int err = lua_pcall(ls, nargs, nret, 0);
set_error(err, ls);