Skip to content

Commit

Permalink
app_lua: restore top index to lua stack after executing a function
Browse files Browse the repository at this point in the history
- could be related to GH #1577

(cherry picked from commit eb96593)
(cherry picked from commit e872f70)
  • Loading branch information
miconda committed Jul 13, 2018
1 parent 645696a commit ed100ad
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/modules/app_lua/app_lua_api.c
Expand Up @@ -646,6 +646,7 @@ int app_lua_run_ex(sip_msg_t *msg, char *func, char *p1, char *p2,
int ret;
str txt;
sip_msg_t *bmsg;
int ltop;

if(_sr_L_env.LL==NULL)
{
Expand All @@ -663,7 +664,8 @@ int app_lua_run_ex(sip_msg_t *msg, char *func, char *p1, char *p2,
}
else LM_DBG("reload deactivated\n");
LM_DBG("executing Lua function: [[%s]]\n", func);
LM_DBG("lua top index is: %d\n", lua_gettop(_sr_L_env.LL));
ltop = lua_gettop(_sr_L_env.LL);
LM_DBG("lua top index is: %d\n", ltop);
lua_getglobal(_sr_L_env.LL, func);
if(!lua_isfunction(_sr_L_env.LL, -1))
{
Expand All @@ -674,8 +676,12 @@ int app_lua_run_ex(sip_msg_t *msg, char *func, char *p1, char *p2,
lua_typename(_sr_L_env.LL,lua_type(_sr_L_env.LL, -1)));
txt.s = (char*)lua_tostring(_sr_L_env.LL, -1);
LM_ERR("error from Lua: %s\n", (txt.s)?txt.s:"unknown");
/* restores the original stack size */
lua_settop(_sr_L_env.LL, ltop);
return -1;
} else {
/* restores the original stack size */
lua_settop(_sr_L_env.LL, ltop);
return 1;
}
}
Expand Down Expand Up @@ -721,13 +727,20 @@ int app_lua_run_ex(sip_msg_t *msg, char *func, char *p1, char *p2,
}
lua_pop(_sr_L_env.LL, 1);
if(n==1) {
/* restores the original stack size */
lua_settop(_sr_L_env.LL, ltop);
return 1;
} else {
LM_ERR("error executing: %s (err: %d)\n", func, ret);
/* restores the original stack size */
lua_settop(_sr_L_env.LL, ltop);
return -1;
}
}

/* restores the original stack size */
lua_settop(_sr_L_env.LL, ltop);

return 1;
}

Expand Down

0 comments on commit ed100ad

Please sign in to comment.