From 79dc1a950197614ae86a29cbf93b41931073e5a9 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 29 Jul 2008 10:43:11 +0200 Subject: [PATCH] lua: dofunction is no more a macro Signed-off-by: Julien Danjou --- lua.h | 50 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/lua.h b/lua.h index 0e54ef32..dd5c9069 100644 --- a/lua.h +++ b/lua.h @@ -77,22 +77,6 @@ typedef int luaA_function; lua_tostring(L, -1)); \ } while(0) -#define luaA_dofunction(L, f, n, r) \ - do { \ - if(f != LUA_REFNIL) \ - { \ - lua_rawgeti(L, LUA_REGISTRYINDEX, f); \ - if(n) \ - lua_insert(L, - (n + 1)); \ - if(lua_pcall(L, n, r, 0)) \ - { \ - warn("error running function: %s", \ - lua_tostring(L, -1)); \ - lua_pop(L, 1); \ - } \ - } \ - } while(0) - #define luaA_checktable(L, n) \ do { \ if(!lua_istable(L, n)) \ @@ -192,6 +176,13 @@ luaA_usemetatable(lua_State *L, int idxobj, int idxfield) return 0; } +/** Register a function. + * \param L The Lua stack. + * \param fct A luaA_function address: it will be filled with the luaA_function + * registered. If the adresse point to an already registered function, it will + * be unregistered. + * \return Always 0. + */ static inline int luaA_registerfct(lua_State *L, luaA_function *fct) { @@ -202,6 +193,33 @@ luaA_registerfct(lua_State *L, luaA_function *fct) return 0; } +/** Execute an Lua function. + * \param L The Lua stack. + * \param f The Lua function to execute. + * \param nargs The number of arguments for the Lua function. + * \param nret The number of returned value from the Lua function. + * \return True on no error, false otherwise. + */ +static inline bool +luaA_dofunction(lua_State *L, luaA_function f, int nargs, int nret) +{ + if(f != LUA_REFNIL) + { + lua_rawgeti(L, LUA_REGISTRYINDEX, f); + if(nargs) + lua_insert(L, - (nargs + 1)); + if(lua_pcall(L, nargs, nret, 0)) + { + warn("error running function: %s", + lua_tostring(L, -1)); + lua_pop(L, 1); + return false; + } + return true; + } + return false; +} + void luaA_init(void); void luaA_parserc(const char *); void luaA_pushpointer(lua_State *, void *, awesome_type_t);