From 7ce53143a6ea781bb9bd2eb29995c6d160331328 Mon Sep 17 00:00:00 2001 From: dshaligram Date: Mon, 25 Jun 2007 19:54:59 +0000 Subject: .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 --- crawl-ref/source/clua.cc | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'crawl-ref/source/clua.cc') 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); -- cgit v1.2.3-54-g00ecf