Modified: freeswitch/trunk/contrib/ledr/lua/lua_dialplan.diff (15324 => 15325)
--- freeswitch/trunk/contrib/ledr/lua/lua_dialplan.diff 2009-11-02 23:31:08 UTC (rev 15324)
+++ freeswitch/trunk/contrib/ledr/lua/lua_dialplan.diff 2009-11-02 23:31:44 UTC (rev 15325)
@@ -1,8 +1,8 @@
Index: mod_lua.cpp
===================================================================
---- mod_lua.cpp (revision 15305)
+--- mod_lua.cpp (revision 15316)
+++ mod_lua.cpp (working copy)
-@@ -461,10 +461,55 @@
+@@ -461,10 +461,104 @@
return SWITCH_STATUS_SUCCESS;
}
@@ -12,8 +12,7 @@
+ switch_caller_extension_t *extension = NULL;
+ switch_channel_t *channel = switch_core_session_get_channel(session);
+ char *cmd;
-+ switch_stream_handle_t stream = { 0 };
-+ SWITCH_STANDARD_STREAM(stream);
++ char *str;
+
+ if (!caller_profile) {
+ if (!(caller_profile = switch_channel_get_caller_profile(channel))) {
@@ -26,7 +25,7 @@
+ caller_profile->context = "lua/dialplan.lua";
+ }
+
-+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Processing %s->%s in script %s\n",
++ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Processing %s->%s in context/script %s\n",
+ caller_profile->caller_id_name, caller_profile->destination_number, caller_profile->context);
+
+ if ((extension = switch_caller_extension_new(session, "_anon_", caller_profile->destination_number)) == 0) {
@@ -38,15 +37,65 @@
+ switch_assert(cmd);
+
+ mod_lua_conjure_session(L, session, "session", 1);
-+ mod_lua_conjure_stream(L, &stream, "stream", 1);
++ lua_parse_and_execute(L, cmd);
+
-+ lua_parse_and_execute(L, cmd); // TODO is it possible to call switch_caller_extension_add_application(session, *extension, application, app_data) from the script ?
-+ lua_uninit(L);
-+ free(cmd);
++ lua_getfield(L, LUA_GLOBALSINDEX, "APPS");
++ if (lua_istable(L, 1)) {
++ lua_gettable(L, 1);
++ while (lua_next(L, -2)) {
++ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "WOOOOOOOT!\n");
++ }
++ }
+
-+ // loop through everything returned by stream:write and add it to 'switch_caller_extension_add_application'
+
++// lua_getfield(L, LUA_GLOBALSINDEX, "APPS");
++// str = strdup(lua_tostring(L, 1));
++// switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, ">>>>> [%s]\n", str);
++// free(str);
++
++/*
++switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, ">>>>> 1\n");
++
++switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "LUA_GETTOP(L) = [%i]\n", lua_gettop(L));
++
++ if (int idx = lua_gettop(L) == 1) {
++switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, ">>>>> 2\n");
++ if (lua_type(L, idx) == LUA_TTABLE) {
++switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, ">>>>> 3\n");
++ lua_gettable(L, idx);
++switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, ">>>>> 4\n");
++ while (lua_next(L, -2)) {
++switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, ">>>>> 5\n");
++ if (lua_isstring(L, -1)) {
++switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, ">>>>> 6\n");
++ char *application = (char *) lua_tostring(L, -1);
++ if (lua_next(L, -2)) {
++switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, ">>>>> 7\n");
++ if (lua_isstring(L, -1)) {
++switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, ">>>>> 8\n");
++ char *app_data = (char *) lua_tostring(L, -1);
++ switch_caller_extension_add_application(session, extension, application, app_data);
++ } else {
++switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, ">>>>> 9\n");
++ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Each app_data must be returned as a string!\n");
++ }
++ }
++ } else {
++switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, ">>>>> 10\n");
++ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Each application must be returned as a string!\n");
++ }
++ }
++ } else {
++switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, ">>>>> 11\n");
++ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Script must return a table!\n");
++ }
++ }
++*/
++
+ done:
++//switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, ">>>>> 12\n");
++ switch_safe_free(cmd);
++ lua_uninit(L);
+ return extension;
+}
+
@@ -58,7 +107,7 @@
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
-@@ -472,6 +517,7 @@
+@@ -472,6 +566,7 @@
SWITCH_ADD_API(api_interface, "luarun", "run a script", luarun_api_function, "<script>");
SWITCH_ADD_API(api_interface, "lua", "run a script as an api function", lua_api_function, "<script>");
SWITCH_ADD_APP(app_interface, "lua", "Launch LUA ivr", "Run a lua ivr on a channel", lua_function, "<script>", SAF_SUPPORT_NOMEDIA);