Modified: freeswitch/trunk/contrib/ledr/lua/lua_dialplan.diff (15327 => 15328)
--- freeswitch/trunk/contrib/ledr/lua/lua_dialplan.diff 2009-11-03 00:52:52 UTC (rev 15327)
+++ freeswitch/trunk/contrib/ledr/lua/lua_dialplan.diff 2009-11-03 10:48:23 UTC (rev 15328)
@@ -1,8 +1,8 @@
-Index: mod_lua.cpp
+Index: src/mod/languages/mod_lua/mod_lua.cpp
===================================================================
---- mod_lua.cpp (revision 15316)
-+++ mod_lua.cpp (working copy)
-@@ -461,10 +461,104 @@
+--- src/mod/languages/mod_lua/mod_lua.cpp (revision 15327)
++++ src/mod/languages/mod_lua/mod_lua.cpp (working copy)
+@@ -461,10 +461,80 @@
return SWITCH_STATUS_SUCCESS;
}
@@ -39,61 +39,37 @@
+ mod_lua_conjure_session(L, session, "session", 1);
+ lua_parse_and_execute(L, cmd);
+
++ /* expecting APPS = { "application1", "app_data1", "application2", "app_data2", "application3" } */
+ 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");
-+ }
-+ }
-+
-+
-+// 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");
-+ }
++ lua_pushnil(L); /* first key */
++ while (lua_next(L, 1) != 0) {
++ /* uses 'key' (at index -2) and 'value' (at index -1) */
++ if (lua_isstring(L, -1)) {
++ char *application;
++ char *app_data;
++ application = strdup(lua_tostring(L, -1));
++ lua_pop(L, 1);
++ if (lua_next(L, 1) != 0) {
++ if (lua_isstring(L, -1)) {
++ app_data = strdup(lua_tostring(L, -1));
++ } else {
++ 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");
+ }
++ switch_caller_extension_add_application(session, extension, application, app_data);
++ switch_safe_free(app_data);
++ switch_safe_free(application);
++ } else {
++ 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");
++ /* removes 'value'; keeps 'key' for next iteration */
++ lua_pop(L, 1);
+ }
++
+ }
-+*/
+
+ done:
-+//switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, ">>>>> 12\n");
+ switch_safe_free(cmd);
+ lua_uninit(L);
+ return extension;
@@ -107,7 +83,7 @@
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
-@@ -472,6 +566,7 @@
+@@ -472,6 +542,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);