FS-6241 --resolve

This commit is contained in:
Anthony Minessale 2014-02-20 01:25:07 +05:00
parent 020c9108a1
commit 99765fbd9a
2 changed files with 39 additions and 24 deletions

View File

@ -4,7 +4,7 @@
using namespace LUA; using namespace LUA;
extern "C" { extern "C" {
int docall(lua_State * L, int narg, int nresults, int perror); int docall(lua_State * L, int narg, int nresults, int perror, int fatal);
}; };
Session::Session():CoreSession() Session::Session():CoreSession()
@ -147,7 +147,7 @@ void Session::do_hangup_hook()
arg_count++; arg_count++;
} }
docall(L, arg_count, 1, 1); docall(L, arg_count, 1, 1, 0);
const char *err = lua_tostring(L, -1); const char *err = lua_tostring(L, -1);
@ -273,6 +273,7 @@ switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t ityp
switch_dtmf_t *dtmf = (switch_dtmf_t *) input; switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
char str[3] = ""; char str[3] = "";
int arg_count = 3; int arg_count = 3;
int r;
lua_getglobal(L, (char *) cb_function); lua_getglobal(L, (char *) cb_function);
lua_getglobal(L, uuid); lua_getglobal(L, uuid);
@ -294,10 +295,14 @@ switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t ityp
arg_count++; arg_count++;
} }
docall(L, arg_count, 1, 1); r = docall(L, arg_count, 1, 1, 0);
if (!r) {
ret = lua_tostring(L, -1); ret = lua_tostring(L, -1);
lua_pop(L, 1); lua_pop(L, 1);
} else {
ret = "SCRIPT_ERROR";
}
return process_callback_result((char *) ret); return process_callback_result((char *) ret);
} }
@ -319,9 +324,12 @@ switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t ityp
arg_count++; arg_count++;
} }
docall(L, arg_count, 1, 1); if (!docall(L, arg_count, 1, 1, 0)) {
ret = lua_tostring(L, -1); ret = lua_tostring(L, -1);
lua_pop(L, 1); lua_pop(L, 1);
} else {
ret = "SCRIPT_ERROR";
}
return process_callback_result((char *) ret); return process_callback_result((char *) ret);
} }
@ -407,7 +415,10 @@ int Dbh::query_callback(void *pArg, int argc, char **argv, char **cargv)
lua_settable(lua_fun->L, -3); lua_settable(lua_fun->L, -3);
} }
docall(lua_fun->L, 1, 1, 1); if (docall(lua_fun->L, 1, 1, 1, 0)) {
return 1;
}
ret = lua_tonumber(lua_fun->L, -1); ret = lua_tonumber(lua_fun->L, -1);
lua_pop(lua_fun->L, 1); lua_pop(lua_fun->L, 1);

View File

@ -81,7 +81,7 @@ static int traceback(lua_State * L)
return 1; return 1;
} }
int docall(lua_State * L, int narg, int nresults, int perror) int docall(lua_State * L, int narg, int nresults, int perror, int fatal)
{ {
int status; int status;
int base = lua_gettop(L) - narg; /* function index */ int base = lua_gettop(L) - narg; /* function index */
@ -102,9 +102,13 @@ int docall(lua_State * L, int narg, int nresults, int perror)
if (!zstr(err)) { if (!zstr(err)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s\n", err); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s\n", err);
} }
//lua_pop(L, 1); /* pop error message from the stack */
// pass error up to top // pass error up to top
if (fatal) {
lua_error(L); lua_error(L);
} else {
lua_pop(L, 1); /* pop error message from the stack */
}
} }
return status; return status;
@ -123,7 +127,7 @@ static lua_State *lua_init(void)
luaopen_freeswitch(L); luaopen_freeswitch(L);
lua_gc(L, LUA_GCRESTART, 0); lua_gc(L, LUA_GCRESTART, 0);
lua_atpanic(L, panic); lua_atpanic(L, panic);
error = luaL_loadbuffer(L, buff, strlen(buff), "line") || docall(L, 0, 0, 0); error = luaL_loadbuffer(L, buff, strlen(buff), "line") || docall(L, 0, 0, 0, 1);
} }
return L; return L;
} }
@ -142,10 +146,10 @@ static int lua_parse_and_execute(lua_State * L, char *input_code)
if (*input_code == '~') { if (*input_code == '~') {
char *buff = input_code + 1; char *buff = input_code + 1;
error = luaL_loadbuffer(L, buff, strlen(buff), "line") || docall(L, 0, 0, 0); //lua_pcall(L, 0, 0, 0); error = luaL_loadbuffer(L, buff, strlen(buff), "line") || docall(L, 0, 0, 0, 1); //lua_pcall(L, 0, 0, 0);
} else if (!strncasecmp(input_code, "#!/lua", 6)) { } else if (!strncasecmp(input_code, "#!/lua", 6)) {
char *buff = input_code + 6; char *buff = input_code + 6;
error = luaL_loadbuffer(L, buff, strlen(buff), "line") || docall(L, 0, 0, 0); //lua_pcall(L, 0, 0, 0); error = luaL_loadbuffer(L, buff, strlen(buff), "line") || docall(L, 0, 0, 0, 1); //lua_pcall(L, 0, 0, 0);
} else { } else {
char *args = strchr(input_code, ' '); char *args = strchr(input_code, ' ');
if (args) { if (args) {
@ -169,14 +173,14 @@ static int lua_parse_and_execute(lua_State * L, char *input_code)
} }
if (code) { if (code) {
error = luaL_loadbuffer(L, code, strlen(code), "line") || docall(L, 0, 0, 0); error = luaL_loadbuffer(L, code, strlen(code), "line") || docall(L, 0, 0, 0, 1);
switch_safe_free(code); switch_safe_free(code);
} }
} else { } else {
// Force empty argv table // Force empty argv table
char *code = NULL; char *code = NULL;
code = switch_mprintf("argv = {[0]='%s'};", input_code); code = switch_mprintf("argv = {[0]='%s'};", input_code);
error = luaL_loadbuffer(L, code, strlen(code), "line") || docall(L, 0, 0, 0); error = luaL_loadbuffer(L, code, strlen(code), "line") || docall(L, 0, 0, 0, 1);
switch_safe_free(code); switch_safe_free(code);
} }
@ -188,7 +192,7 @@ static int lua_parse_and_execute(lua_State * L, char *input_code)
switch_assert(fdup); switch_assert(fdup);
file = fdup; file = fdup;
} }
error = luaL_loadfile(L, file) || docall(L, 0, 0, 0); error = luaL_loadfile(L, file) || docall(L, 0, 0, 0, 1);
switch_safe_free(fdup); switch_safe_free(fdup);
} }
} }