summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/clua.cc
diff options
context:
space:
mode:
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);