提交 cf3ceb57 authored 作者: Leon de Rooij's avatar Leon de Rooij

Seems to work :-)

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk/contrib@15328 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 7d9f19c9
Index: mod_lua.cpp Index: src/mod/languages/mod_lua/mod_lua.cpp
=================================================================== ===================================================================
--- mod_lua.cpp (revision 15316) --- src/mod/languages/mod_lua/mod_lua.cpp (revision 15327)
+++ mod_lua.cpp (working copy) +++ src/mod/languages/mod_lua/mod_lua.cpp (working copy)
@@ -461,10 +461,104 @@ @@ -461,10 +461,80 @@
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
...@@ -39,61 +39,37 @@ Index: mod_lua.cpp ...@@ -39,61 +39,37 @@ Index: mod_lua.cpp
+ mod_lua_conjure_session(L, session, "session", 1); + mod_lua_conjure_session(L, session, "session", 1);
+ lua_parse_and_execute(L, cmd); + lua_parse_and_execute(L, cmd);
+ +
+ /* expecting APPS = { "application1", "app_data1", "application2", "app_data2", "application3" } */
+ lua_getfield(L, LUA_GLOBALSINDEX, "APPS"); + lua_getfield(L, LUA_GLOBALSINDEX, "APPS");
+ if (lua_istable(L, 1)) { + if (lua_istable(L, 1)) {
+ lua_gettable(L, 1); + lua_pushnil(L); /* first key */
+ while (lua_next(L, -2)) { + while (lua_next(L, 1) != 0) {
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "WOOOOOOOT!\n"); + /* 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_getfield(L, LUA_GLOBALSINDEX, "APPS"); + lua_pop(L, 1);
+// str = strdup(lua_tostring(L, 1)); + if (lua_next(L, 1) != 0) {
+// switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, ">>>>> [%s]\n", str); + if (lua_isstring(L, -1)) {
+// free(str); + 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");
+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");
+ } + }
+ 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 { + /* removes 'value'; keeps 'key' for next iteration */
+switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, ">>>>> 11\n"); + lua_pop(L, 1);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Script must return a table!\n");
+ } + }
+
+ } + }
+*/
+ +
+ done: + done:
+//switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, ">>>>> 12\n");
+ switch_safe_free(cmd); + switch_safe_free(cmd);
+ lua_uninit(L); + lua_uninit(L);
+ return extension; + return extension;
...@@ -107,7 +83,7 @@ Index: mod_lua.cpp ...@@ -107,7 +83,7 @@ Index: mod_lua.cpp
/* connect my internal structure to the blank pointer passed to me */ /* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname); *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, "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_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); SWITCH_ADD_APP(app_interface, "lua", "Launch LUA ivr", "Run a lua ivr on a channel", lua_function, "<script>", SAF_SUPPORT_NOMEDIA);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论