}
-static void lua_parse_and_execute(lua_State *L, char *input_code)
+static int lua_parse_and_execute(lua_State *L, char *input_code)
{
int error = 0;
if (switch_strlen_zero(input_code)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No code to execute!\n");
- return;
+ return 1;
}
if (*input_code == '~') {
}
lua_pop(L, 1); /* pop error message from the stack */
}
+
+ return error;
}
static void *SWITCH_THREAD_FUNC lua_thread_run(switch_thread_t *thread, void *obj)
lua_State *L = lua_init();
char code[1024] = "";
char *mycmd;
+ int error;
+
if (switch_strlen_zero(data)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "no args specified!\n");
return;
}
snprintf(code, sizeof(code), "~session = freeswitch.Session(\"%s\");", switch_core_session_get_uuid(session));
- lua_parse_and_execute(L, code);
+ error = lua_parse_and_execute(L, code);
mycmd = strdup((char *)data);
switch_assert(mycmd);
lua_parse_and_execute(L, mycmd);
lua_uninit(L);
free(mycmd);
+
}
SWITCH_STANDARD_API(luarun_api_function) {
-
+
if (switch_strlen_zero(cmd)) {
stream->write_function(stream, "-ERR no args specified!\n");
} else {
lua_State *L = lua_init();
char *mycmd;
-
+ int error;
+
if (switch_strlen_zero(cmd)) {
stream->write_function(stream, "");
} else {
mod_lua_conjure_event(L, stream->event, "env", 1);
}
- lua_parse_and_execute(L, mycmd);
+ if ((error = lua_parse_and_execute(L, mycmd))) {
+ if (switch_event_get_header(stream->event, "http-host")) {
+ stream->write_function(stream, "Content-Type: text/html\n\n<H2>Error Executing Script</H2>");
+ } else {
+ stream->write_function(stream, "-ERR encounterd\n");
+ }
+ }
lua_uninit(L);
free(mycmd);
}