lua: dofunction is no more a macro

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-07-29 10:43:11 +02:00
parent 4e577f9fed
commit 79dc1a9501
1 changed files with 34 additions and 16 deletions

50
lua.h
View File

@ -77,22 +77,6 @@ typedef int luaA_function;
lua_tostring(L, -1)); \ lua_tostring(L, -1)); \
} while(0) } 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) \ #define luaA_checktable(L, n) \
do { \ do { \
if(!lua_istable(L, n)) \ if(!lua_istable(L, n)) \
@ -192,6 +176,13 @@ luaA_usemetatable(lua_State *L, int idxobj, int idxfield)
return 0; 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 static inline int
luaA_registerfct(lua_State *L, luaA_function *fct) luaA_registerfct(lua_State *L, luaA_function *fct)
{ {
@ -202,6 +193,33 @@ luaA_registerfct(lua_State *L, luaA_function *fct)
return 0; 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_init(void);
void luaA_parserc(const char *); void luaA_parserc(const char *);
void luaA_pushpointer(lua_State *, void *, awesome_type_t); void luaA_pushpointer(lua_State *, void *, awesome_type_t);