From 267e829cbd00e655a9d6aaf8e2dcaa644ca94bea Mon Sep 17 00:00:00 2001 From: Jason Parker Date: Thu, 8 Nov 2007 23:38:30 +0000 Subject: [PATCH] Add check_hangup() method to pbx_lua, which can be used to check whether it is time to hangup a channel. Closes issue #11202, patch by mnicholson git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89124 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- pbx/pbx_lua.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/pbx/pbx_lua.c b/pbx/pbx_lua.c index 193f031a57..0465ff9721 100644 --- a/pbx/pbx_lua.c +++ b/pbx/pbx_lua.c @@ -73,6 +73,7 @@ static int lua_func_read(lua_State *L); static int lua_autoservice_start(lua_State *L); static int lua_autoservice_stop(lua_State *L); static int lua_autoservice_status(lua_State *L); +static int lua_check_hangup(lua_State *L); static void lua_update_registry(lua_State *L, const char *context, const char *exten, int priority); static void lua_push_variable_table(lua_State *L, const char *name); @@ -81,6 +82,7 @@ static void lua_create_channel_table(lua_State *L); static void lua_create_variable_metatable(lua_State *L); static void lua_create_application_metatable(lua_State *L); static void lua_create_autoservice_functions(lua_State *L); +static void lua_create_hangup_function(lua_State *L); void lua_state_destroy(void *data); static lua_State *lua_get_state(struct ast_channel *chan); @@ -478,6 +480,17 @@ static void lua_create_autoservice_functions(lua_State *L) lua_setfield(L, LUA_REGISTRYINDEX, "autoservice"); } +/*! + * \brief Create the hangup check function + * + * \param L the lua_State to use + */ +static void lua_create_hangup_function(lua_State *L) +{ + lua_pushcfunction(L, &lua_check_hangup); + lua_setglobal(L, "check_hangup"); +} + /*! * \brief [lua_CFunction] Return a lua 'variable' object (for access from lua, don't call * directly) @@ -682,6 +695,25 @@ static int lua_autoservice_status(lua_State *L) return 1; } +/*! + * \brief [lua_CFunction] Check if this channel has been hungup or not (for + * access from lua, don't call directly) + * + * \param L the lua_State to use + * + * \return This function returns true if the channel was hungup + */ +static int lua_check_hangup(lua_State *L) +{ + struct ast_channel *chan; + lua_getfield(L, LUA_REGISTRYINDEX, "channel"); + chan = lua_touserdata(L, -1); + lua_pop(L, 1); + + lua_pushboolean(L, ast_check_hangup(chan)); + return 1; +} + /*! * \brief Store the sort order of each context @@ -872,6 +904,7 @@ static int lua_load_extensions(lua_State *L, struct ast_channel *chan) lua_create_application_metatable(L); lua_create_autoservice_functions(L); + lua_create_hangup_function(L); return 0; }