[asterisk-commits] tilghman: trunk r88250 - in /trunk: ./ build_tools/ configs/ include/asterisk...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Nov 2 10:36:35 CDT 2007


Author: tilghman
Date: Fri Nov  2 10:36:34 2007
New Revision: 88250

URL: http://svn.digium.com/view/asterisk?view=rev&rev=88250
Log:
Add pbx_lua as a method of doing extensions

Added:
    trunk/configs/extensions.lua.sample   (with props)
    trunk/pbx/pbx_lua.c   (with props)
    trunk/utils/build-extensions-conf.lua   (with props)
Modified:
    trunk/build_tools/menuselect-deps.in
    trunk/configure
    trunk/configure.ac
    trunk/include/asterisk/autoconfig.h.in
    trunk/include/asterisk/pbx.h
    trunk/main/pbx.c
    trunk/makeopts.in

Modified: trunk/build_tools/menuselect-deps.in
URL: http://svn.digium.com/view/asterisk/trunk/build_tools/menuselect-deps.in?view=diff&rev=88250&r1=88249&r2=88250
==============================================================================
--- trunk/build_tools/menuselect-deps.in (original)
+++ trunk/build_tools/menuselect-deps.in Fri Nov  2 10:36:34 2007
@@ -11,6 +11,7 @@
 IXJUSER=@PBX_IXJUSER@
 KDE=@PBX_KDE@
 LTDL=@PBX_LTDL@
+LUA=@PBX_LUA@
 NBS=@PBX_NBS@
 NETSNMP=@PBX_NETSNMP@
 NEWT=@PBX_NEWT@

Added: trunk/configs/extensions.lua.sample
URL: http://svn.digium.com/view/asterisk/trunk/configs/extensions.lua.sample?view=auto&rev=88250
==============================================================================
--- trunk/configs/extensions.lua.sample (added)
+++ trunk/configs/extensions.lua.sample Fri Nov  2 10:36:34 2007
@@ -1,0 +1,208 @@
+
+
+CONSOLE = "Console/dsp" -- Console interface for demo
+--CONSOLE = "Zap/1"
+--CONSOLE = "Phone/phone0"
+
+IAXINFO = "guest"       -- IAXtel username/password
+--IAXINFO = "myuser:mypass"
+
+TRUNK = "Zap/g2"
+TRUNKMSD = 1
+-- TRUNK = "IAX2/user:pass at provider"
+
+
+--
+-- Extensions are expected to be defined in a global table named 'extensions'.
+-- The 'extensions' table should have a group of tables in it, each
+-- representing a context.  Extensions are defined in each context.  See below
+-- for examples.
+--
+-- This file can be automatically included in the extensions.conf file using
+-- the 'utils/build-extensions-conf.lua' script and a #exec statement in
+-- extensions.conf.
+--
+--   #exec /usr/bin/utils/build-extensions.conf.lua -c
+-- 
+-- The 'execincludes' option must be set to 'yes' in the [options] section of
+-- asterisk.conf for this to work properly.
+-- 
+-- Extension names may be numbers, letters, or combinations thereof. If
+-- an extension name is prefixed by a '_' character, it is interpreted as
+-- a pattern rather than a literal.  In patterns, some characters have
+-- special meanings:
+--                                                                           
+--   X - any digit from 0-9
+--   Z - any digit from 1-9
+--   N - any digit from 2-9
+--   [1235-9] - any digit in the brackets (in this example, 1,2,3,5,6,7,8,9)
+--   . - wildcard, matches anything remaining (e.g. _9011. matches 
+--       anything starting with 9011 excluding 9011 itself)
+--   ! - wildcard, causes the matching process to complete as soon as
+--       it can unambiguously determine that no other matches are possible
+--                                                                           
+-- For example the extension _NXXXXXX would match normal 7 digit
+-- dialings, while _1NXXNXXXXXX would represent an area code plus phone
+-- number preceded by a one.
+-- 
+-- If your extension has special characters in it such as '.' and '!' you must
+-- explicitly make it a string in the tabale definition:
+--
+--   ["_special."] = function;
+--   ["_special!"] = function;
+--
+-- There are no priorities.  All extensions to asterisk appear to have a single
+-- priority as if they consist of a single priority.
+-- 
+-- Each context is defined as a table in the extensions table.  The
+-- context names should be strings.
+--
+-- One context may be included in another context using the 'includes'
+-- extension.  This extension should be set to a table containing a list
+-- of context names.  Do not put references to tables in the includes
+-- table.
+-- 
+--   include = {"a", "b", "c"};
+--
+-- Channel variables can be accessed thorugh the global 'channel' table.
+--
+--   v = channel.var_name
+--   v = channel["var_name"]
+--   v.value
+--   v:get()
+--
+--   channel.var_name = "value"
+--   channel["var_name"] = "value"
+--   v:set("value")
+--
+--   channel.func_name(1,2,3):set("value")
+--   value = channel.func_name(1,2,3):get()
+--
+--   channel["func_name(1|2|3)"]:set("value")
+--   channel["func_name(1|2|3)"] = "value"
+--   value = channel["func_name(1|2|3)"]:get()
+--
+-- Note the use of the ':' operator to access the get() and set()
+-- methods.
+--
+-- Also notice the absence of the following constructs from the examples above:
+--   channel.func_name(1,2,3) = "value"  -- this will NOT work
+--   value = channel.func_name(1,2,3)    -- this will NOT work as expected
+-- 
+--
+-- Dialplan applications can be accessed through the global 'app' table.
+--
+--    app.Dial("Zap/1")
+--    app.dial("Zap/1")
+--
+-- More examples can be found below.
+--
+-- Before starting long running operations, an autoservice should be started
+-- using the autoservice_start() function.  This autoservice will automatically
+-- be stopped before executing applications and dialplan functions and will be
+-- restarted afterwards.  The autoservice can be stopped using
+-- autoservice_stop() and the autoservice_status() function will return true if
+-- an autoservice is currently running.
+--
+
+function outgoing_local(c, e)
+	app.dial("zap/1/" .. e, "", "")
+end
+
+function demo_instruct()
+	app.background("demo-instruct")
+	app.waitexten()
+end
+
+function demo_congrats()
+	app.background("demo-congrats")
+	demo_instruct()
+end
+
+-- Answer the chanel and play the demo sound files
+function demo_start(context, exten)
+	app.wait(1)
+	app.answer()
+
+	channel.TIMEOUT("digit"):set(5)
+	channel.TIMEOUT("response"):set(10)
+	-- app.set("TIMEOUT(digit)=5")
+	-- app.set("TIMEOUT(response)=10")
+
+	demo_congrats(context, exten)
+end
+
+function demo_hangup()
+	app.playback("demo-thanks")
+	app.hangup()
+end
+
+extensions = {
+	demo = {
+		s = demo_start;
+
+		["2"] = function()
+			app.background("demo-moreinfo")
+			demo_instruct()
+		end;
+		["3"] = function ()
+			channel.LANGUAGE():set("fr") -- set the language to french
+			demo_congrats()
+		end;
+
+		["1000"] = function()
+			app.goto("default", "s", 1)
+		end;
+
+		["1234"] = function()
+			app.playback("transfer", "skip")
+			-- do a dial here
+		end;
+
+		["1235"] = function()
+			app.voicemail("1234", "u")
+		end;
+
+		["1236"] = function()
+			app.dial("Console/dsp")
+			app.voicemail(1234, "b")
+		end;
+
+		["#"] = demo_hangup;
+		t = demo_hangup;
+                i = function()
+                        app.playback("invalid")
+                        demo_instruct()
+                end;
+
+		["500"] = function()
+			app.playback("demo-abouttotry")
+			app.dial("IAX2/guest at misery.digium.com/s at default")
+			app.playback("demo-nogo")
+			demo_instruct()
+		end;
+
+		["600"] = function()
+			app.playback("demo-echotest")
+			app.echo()
+			app.playback("demo-echodone")
+			demo_instruct()
+		end;
+
+		["8500"] = function()
+			app.voicemailmain()
+			demo_instruct()
+		end;
+
+	};
+
+	default = {
+		-- by default, do the demo
+		include = {"demo"};
+	};
+
+	["local"] = {
+		["_NXXXXXX"] = outgoing_local;
+	};
+}
+

Propchange: trunk/configs/extensions.lua.sample
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: trunk/configs/extensions.lua.sample
------------------------------------------------------------------------------
    svn:keywords = Id Date Author Revision

Propchange: trunk/configs/extensions.lua.sample
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: trunk/configure
URL: http://svn.digium.com/view/asterisk/trunk/configure?view=diff&rev=88250&r1=88249&r2=88250
==============================================================================
--- trunk/configure (original)
+++ trunk/configure Fri Nov  2 10:36:34 2007
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.ac Revision: 87325 .
+# From configure.ac Revision: 88184 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.61.
 #
@@ -765,6 +765,10 @@
 LTDL_INCLUDE
 LTDL_DIR
 PBX_LTDL
+LUA_LIB
+LUA_INCLUDE
+LUA_DIR
+PBX_LUA
 MISDN_LIB
 MISDN_INCLUDE
 MISDN_DIR
@@ -1537,6 +1541,7 @@
   --with-isdnnet=PATH     use ISDN4Linux Library files in PATH
   --with-kde=PATH         use KDE files in PATH
   --with-ltdl=PATH        use libtool files in PATH
+  --with-lua=PATH         use Lua files in PATH
   --with-misdn=PATH       use mISDN User Library files in PATH
   --with-nbs=PATH         use Network Broadcast Sound files in PATH
   --with-ncurses=PATH     use ncurses files in PATH
@@ -7985,6 +7990,34 @@
 fi
 
 PBX_LTDL=0
+
+
+
+
+
+
+LUA_DESCRIP="Lua"
+LUA_OPTION="lua"
+
+# Check whether --with-lua was given.
+if test "${with_lua+set}" = set; then
+  withval=$with_lua;
+case ${withval} in
+     n|no)
+     USE_LUA=no
+     ;;
+     y|ye|yes)
+     ac_mandatory_list="${ac_mandatory_list} LUA"
+     ;;
+     *)
+     LUA_DIR="${withval}"
+     ac_mandatory_list="${ac_mandatory_list} LUA"
+     ;;
+esac
+
+fi
+
+PBX_LUA=0
 
 
 
@@ -47070,6 +47103,399 @@
 ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
 ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
 ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+LUA_INCLUDE="-I/usr/include/lua5.1"
+LUA_LIB="-llua5.1"
+
+if test "x${PBX_LUA}" != "x1" -a "${USE_LUA}" != "no"; then
+   pbxlibdir=""
+   if test "x${LUA_DIR}" != "x"; then
+      if test -d ${LUA_DIR}/lib; then
+      	 pbxlibdir="-L${LUA_DIR}/lib"
+      else
+      	 pbxlibdir="-L${LUA_DIR}"
+      fi
+   fi
+   pbxfuncname="luaL_newstate"
+   if test "x${pbxfuncname}" = "x" ; then   # empty lib, assume only headers
+      AST_LUA_FOUND=yes
+   else
+      as_ac_Lib=`echo "ac_cv_lib_lua5.1_${pbxfuncname}" | $as_tr_sh`
+{ echo "$as_me:$LINENO: checking for ${pbxfuncname} in -llua5.1" >&5
+echo $ECHO_N "checking for ${pbxfuncname} in -llua5.1... $ECHO_C" >&6; }
+if { as_var=$as_ac_Lib; eval "test \"\${$as_var+set}\" = set"; }; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-llua5.1 ${pbxlibdir}  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char ${pbxfuncname} ();
+int
+main ()
+{
+return ${pbxfuncname} ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+  eval "$as_ac_Lib=yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	eval "$as_ac_Lib=no"
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+ac_res=`eval echo '${'$as_ac_Lib'}'`
+	       { echo "$as_me:$LINENO: result: $ac_res" >&5
+echo "${ECHO_T}$ac_res" >&6; }
+if test `eval echo '${'$as_ac_Lib'}'` = yes; then
+  AST_LUA_FOUND=yes
+else
+  AST_LUA_FOUND=no
+fi
+
+   fi
+
+   if test "${AST_LUA_FOUND}" = "yes"; then
+      LUA_LIB="-llua5.1 "
+      LUA_HEADER_FOUND="1"
+      if test "x${LUA_DIR}" != "x"; then
+         LUA_LIB="${pbxlibdir} ${LUA_LIB}"
+	 LUA_INCLUDE="-I${LUA_DIR}/include"
+	 saved_cppflags="${CPPFLAGS}"
+	 CPPFLAGS="${CPPFLAGS} -I${LUA_DIR}/include"
+	 if test "xlua5.1/lua.h" != "x" ; then
+	    as_ac_Header=`echo "ac_cv_header_${LUA_DIR}/include/lua5.1/lua.h" | $as_tr_sh`
+if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
+  { echo "$as_me:$LINENO: checking for ${LUA_DIR}/include/lua5.1/lua.h" >&5
+echo $ECHO_N "checking for ${LUA_DIR}/include/lua5.1/lua.h... $ECHO_C" >&6; }
+if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+fi
+ac_res=`eval echo '${'$as_ac_Header'}'`
+	       { echo "$as_me:$LINENO: result: $ac_res" >&5
+echo "${ECHO_T}$ac_res" >&6; }
+else
+  # Is the header compilable?
+{ echo "$as_me:$LINENO: checking ${LUA_DIR}/include/lua5.1/lua.h usability" >&5
+echo $ECHO_N "checking ${LUA_DIR}/include/lua5.1/lua.h usability... $ECHO_C" >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+#include <${LUA_DIR}/include/lua5.1/lua.h>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_header_compiler=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_header_compiler=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
+echo "${ECHO_T}$ac_header_compiler" >&6; }
+
+# Is the header present?
+{ echo "$as_me:$LINENO: checking ${LUA_DIR}/include/lua5.1/lua.h presence" >&5
+echo $ECHO_N "checking ${LUA_DIR}/include/lua5.1/lua.h presence... $ECHO_C" >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <${LUA_DIR}/include/lua5.1/lua.h>
+_ACEOF
+if { (ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null && {
+	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       }; then
+  ac_header_preproc=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  ac_header_preproc=no
+fi
+
+rm -f conftest.err conftest.$ac_ext
+{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
+echo "${ECHO_T}$ac_header_preproc" >&6; }
+
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
+  yes:no: )
+    { echo "$as_me:$LINENO: WARNING: ${LUA_DIR}/include/lua5.1/lua.h: accepted by the compiler, rejected by the preprocessor!" >&5
+echo "$as_me: WARNING: ${LUA_DIR}/include/lua5.1/lua.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { echo "$as_me:$LINENO: WARNING: ${LUA_DIR}/include/lua5.1/lua.h: proceeding with the compiler's result" >&5
+echo "$as_me: WARNING: ${LUA_DIR}/include/lua5.1/lua.h: proceeding with the compiler's result" >&2;}
+    ac_header_preproc=yes
+    ;;
+  no:yes:* )
+    { echo "$as_me:$LINENO: WARNING: ${LUA_DIR}/include/lua5.1/lua.h: present but cannot be compiled" >&5
+echo "$as_me: WARNING: ${LUA_DIR}/include/lua5.1/lua.h: present but cannot be compiled" >&2;}
+    { echo "$as_me:$LINENO: WARNING: ${LUA_DIR}/include/lua5.1/lua.h:     check for missing prerequisite headers?" >&5
+echo "$as_me: WARNING: ${LUA_DIR}/include/lua5.1/lua.h:     check for missing prerequisite headers?" >&2;}
+    { echo "$as_me:$LINENO: WARNING: ${LUA_DIR}/include/lua5.1/lua.h: see the Autoconf documentation" >&5
+echo "$as_me: WARNING: ${LUA_DIR}/include/lua5.1/lua.h: see the Autoconf documentation" >&2;}
+    { echo "$as_me:$LINENO: WARNING: ${LUA_DIR}/include/lua5.1/lua.h:     section \"Present But Cannot Be Compiled\"" >&5
+echo "$as_me: WARNING: ${LUA_DIR}/include/lua5.1/lua.h:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { echo "$as_me:$LINENO: WARNING: ${LUA_DIR}/include/lua5.1/lua.h: proceeding with the preprocessor's result" >&5
+echo "$as_me: WARNING: ${LUA_DIR}/include/lua5.1/lua.h: proceeding with the preprocessor's result" >&2;}
+    { echo "$as_me:$LINENO: WARNING: ${LUA_DIR}/include/lua5.1/lua.h: in the future, the compiler will take precedence" >&5
+echo "$as_me: WARNING: ${LUA_DIR}/include/lua5.1/lua.h: in the future, the compiler will take precedence" >&2;}
+
+    ;;
+esac
+{ echo "$as_me:$LINENO: checking for ${LUA_DIR}/include/lua5.1/lua.h" >&5
+echo $ECHO_N "checking for ${LUA_DIR}/include/lua5.1/lua.h... $ECHO_C" >&6; }
+if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  eval "$as_ac_Header=\$ac_header_preproc"
+fi
+ac_res=`eval echo '${'$as_ac_Header'}'`
+	       { echo "$as_me:$LINENO: result: $ac_res" >&5
+echo "${ECHO_T}$ac_res" >&6; }
+
+fi
+if test `eval echo '${'$as_ac_Header'}'` = yes; then
+  LUA_HEADER_FOUND=1
+else
+  LUA_HEADER_FOUND=0
+fi
+
+
+	 fi
+	 CPPFLAGS="${saved_cppflags}"
+      else
+	 if test "xlua5.1/lua.h" != "x" ; then
+            if test "${ac_cv_header_lua5_1_lua_h+set}" = set; then
+  { echo "$as_me:$LINENO: checking for lua5.1/lua.h" >&5
+echo $ECHO_N "checking for lua5.1/lua.h... $ECHO_C" >&6; }
+if test "${ac_cv_header_lua5_1_lua_h+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_header_lua5_1_lua_h" >&5
+echo "${ECHO_T}$ac_cv_header_lua5_1_lua_h" >&6; }
+else
+  # Is the header compilable?
+{ echo "$as_me:$LINENO: checking lua5.1/lua.h usability" >&5
+echo $ECHO_N "checking lua5.1/lua.h usability... $ECHO_C" >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+#include <lua5.1/lua.h>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_header_compiler=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_header_compiler=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
+echo "${ECHO_T}$ac_header_compiler" >&6; }
+
+# Is the header present?
+{ echo "$as_me:$LINENO: checking lua5.1/lua.h presence" >&5
+echo $ECHO_N "checking lua5.1/lua.h presence... $ECHO_C" >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <lua5.1/lua.h>
+_ACEOF
+if { (ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null && {
+	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       }; then
+  ac_header_preproc=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  ac_header_preproc=no
+fi
+
+rm -f conftest.err conftest.$ac_ext
+{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
+echo "${ECHO_T}$ac_header_preproc" >&6; }
+
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
+  yes:no: )
+    { echo "$as_me:$LINENO: WARNING: lua5.1/lua.h: accepted by the compiler, rejected by the preprocessor!" >&5
+echo "$as_me: WARNING: lua5.1/lua.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { echo "$as_me:$LINENO: WARNING: lua5.1/lua.h: proceeding with the compiler's result" >&5
+echo "$as_me: WARNING: lua5.1/lua.h: proceeding with the compiler's result" >&2;}
+    ac_header_preproc=yes
+    ;;
+  no:yes:* )
+    { echo "$as_me:$LINENO: WARNING: lua5.1/lua.h: present but cannot be compiled" >&5
+echo "$as_me: WARNING: lua5.1/lua.h: present but cannot be compiled" >&2;}
+    { echo "$as_me:$LINENO: WARNING: lua5.1/lua.h:     check for missing prerequisite headers?" >&5
+echo "$as_me: WARNING: lua5.1/lua.h:     check for missing prerequisite headers?" >&2;}
+    { echo "$as_me:$LINENO: WARNING: lua5.1/lua.h: see the Autoconf documentation" >&5
+echo "$as_me: WARNING: lua5.1/lua.h: see the Autoconf documentation" >&2;}
+    { echo "$as_me:$LINENO: WARNING: lua5.1/lua.h:     section \"Present But Cannot Be Compiled\"" >&5
+echo "$as_me: WARNING: lua5.1/lua.h:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { echo "$as_me:$LINENO: WARNING: lua5.1/lua.h: proceeding with the preprocessor's result" >&5
+echo "$as_me: WARNING: lua5.1/lua.h: proceeding with the preprocessor's result" >&2;}
+    { echo "$as_me:$LINENO: WARNING: lua5.1/lua.h: in the future, the compiler will take precedence" >&5
+echo "$as_me: WARNING: lua5.1/lua.h: in the future, the compiler will take precedence" >&2;}
+
+    ;;
+esac
+{ echo "$as_me:$LINENO: checking for lua5.1/lua.h" >&5
+echo $ECHO_N "checking for lua5.1/lua.h... $ECHO_C" >&6; }
+if test "${ac_cv_header_lua5_1_lua_h+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_cv_header_lua5_1_lua_h=$ac_header_preproc
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_header_lua5_1_lua_h" >&5
+echo "${ECHO_T}$ac_cv_header_lua5_1_lua_h" >&6; }
+
+fi
+if test $ac_cv_header_lua5_1_lua_h = yes; then
+  LUA_HEADER_FOUND=1
+else
+  LUA_HEADER_FOUND=0
+fi
+
+
+	 fi
+      fi
+      if test "x${LUA_HEADER_FOUND}" = "x0" ; then
+         LUA_LIB=""
+         LUA_INCLUDE=""
+      else
+         if test "x${pbxfuncname}" = "x" ; then		# only checking headers -> no library
+	    LUA_LIB=""
+	 fi
+         PBX_LUA=1
+         # XXX don't know how to evaluate the description (third argument) in AC_DEFINE_UNQUOTED
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_LUA 1
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_LUA_VERSION
+_ACEOF
+
+      fi
+   fi
+fi
 
 
 
@@ -56493,6 +56919,10 @@
 LTDL_INCLUDE!$LTDL_INCLUDE$ac_delim
 LTDL_DIR!$LTDL_DIR$ac_delim
 PBX_LTDL!$PBX_LTDL$ac_delim
+LUA_LIB!$LUA_LIB$ac_delim
+LUA_INCLUDE!$LUA_INCLUDE$ac_delim
+LUA_DIR!$LUA_DIR$ac_delim
+PBX_LUA!$PBX_LUA$ac_delim
 MISDN_LIB!$MISDN_LIB$ac_delim
 MISDN_INCLUDE!$MISDN_INCLUDE$ac_delim
 MISDN_DIR!$MISDN_DIR$ac_delim
@@ -56537,10 +56967,6 @@
 PGSQL_INCLUDE!$PGSQL_INCLUDE$ac_delim
 PGSQL_DIR!$PGSQL_DIR$ac_delim
 PBX_PGSQL!$PBX_PGSQL$ac_delim
-PRI_LIB!$PRI_LIB$ac_delim
-PRI_INCLUDE!$PRI_INCLUDE$ac_delim
-PRI_DIR!$PRI_DIR$ac_delim
-PBX_PRI!$PBX_PRI$ac_delim
 _ACEOF
 
   if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 97; then
@@ -56582,6 +57008,10 @@
 ac_delim='%!_!# '
 for ac_last_try in false false false false false :; do
   cat >conf$$subs.sed <<_ACEOF
+PRI_LIB!$PRI_LIB$ac_delim
+PRI_INCLUDE!$PRI_INCLUDE$ac_delim
+PRI_DIR!$PRI_DIR$ac_delim
+PBX_PRI!$PBX_PRI$ac_delim
 SS7_LIB!$SS7_LIB$ac_delim
 SS7_INCLUDE!$SS7_INCLUDE$ac_delim
 SS7_DIR!$SS7_DIR$ac_delim
@@ -56675,10 +57105,6 @@
 GSM_INTERNAL!$GSM_INTERNAL$ac_delim
 KDEINIT!$KDEINIT$ac_delim
 KDEDIR!$KDEDIR$ac_delim
-NETSNMP_CONFIG!$NETSNMP_CONFIG$ac_delim
-PG_CONFIG!$PG_CONFIG$ac_delim
-PTLIB_CONFIG!$PTLIB_CONFIG$ac_delim
-PWLIBDIR!$PWLIBDIR$ac_delim
 _ACEOF
 
   if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 97; then
@@ -56720,6 +57146,10 @@
 ac_delim='%!_!# '
 for ac_last_try in false false false false false :; do
   cat >conf$$subs.sed <<_ACEOF
+NETSNMP_CONFIG!$NETSNMP_CONFIG$ac_delim
+PG_CONFIG!$PG_CONFIG$ac_delim
+PTLIB_CONFIG!$PTLIB_CONFIG$ac_delim
+PWLIBDIR!$PWLIBDIR$ac_delim
 PWLIB_INCDIR!$PWLIB_INCDIR$ac_delim
 PWLIB_LIBDIR!$PWLIB_LIBDIR$ac_delim
 PWLIB_PLATFORM!$PWLIB_PLATFORM$ac_delim
@@ -56744,7 +57174,7 @@
 LTLIBOBJS!$LTLIBOBJS$ac_delim
 _ACEOF
 
-  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 22; then
+  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 26; then
     break
   elif $ac_last_try; then
     { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5

Modified: trunk/configure.ac
URL: http://svn.digium.com/view/asterisk/trunk/configure.ac?view=diff&rev=88250&r1=88249&r2=88250
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Fri Nov  2 10:36:34 2007
@@ -193,6 +193,7 @@
 AST_EXT_LIB_SETUP([ISDNNET], [ISDN4Linux Library], [isdnnet])
 AST_EXT_LIB_SETUP([KDE], [KDE], [kde])
 AST_EXT_LIB_SETUP([LTDL], [libtool], [ltdl])
+AST_EXT_LIB_SETUP([LUA], [Lua], [lua])
 AST_EXT_LIB_SETUP([MISDN], [mISDN User Library], [misdn])
 AST_EXT_LIB_SETUP([NBS], [Network Broadcast Sound], [nbs])
 AST_EXT_LIB_SETUP([NCURSES], [ncurses], [ncurses])
@@ -980,6 +981,10 @@
 
 AC_LANG_POP
 
+LUA_INCLUDE="-I/usr/include/lua5.1"
+LUA_LIB="-llua5.1"
+AST_EXT_LIB_CHECK([LUA], [lua5.1], [luaL_newstate], [lua5.1/lua.h]) 
+
 AST_EXT_LIB_CHECK([RADIUS], [radiusclient-ng], [rc_read_config], [radiusclient-ng.h])
 
 AST_EXT_LIB_CHECK([SPEEX], [speex], [speex_encode], [speex/speex.h], [-lm])

Modified: trunk/include/asterisk/autoconfig.h.in
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/autoconfig.h.in?view=diff&rev=88250&r1=88249&r2=88250
==============================================================================
--- trunk/include/asterisk/autoconfig.h.in (original)
+++ trunk/include/asterisk/autoconfig.h.in Fri Nov  2 10:36:34 2007
@@ -408,6 +408,12 @@
 
 /* Define to indicate the ${LTDL_DESCRIP} library version */
 #undef HAVE_LTDL_VERSION
+
+/* Define this to indicate the ${LUA_DESCRIP} library */
+#undef HAVE_LUA
+
+/* Define to indicate the ${LUA_DESCRIP} library version */
+#undef HAVE_LUA_VERSION
 
 /* Define to 1 if you have the <malloc.h> header file. */
 #undef HAVE_MALLOC_H

Modified: trunk/include/asterisk/pbx.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/pbx.h?view=diff&rev=88250&r1=88249&r2=88250
==============================================================================
--- trunk/include/asterisk/pbx.h (original)
+++ trunk/include/asterisk/pbx.h Fri Nov  2 10:36:34 2007
@@ -508,6 +508,20 @@
 int ast_extension_close(const char *pattern, const char *data, int needmore);
 
 /*! 
+ * \brief Determine if one extension should match before another
+ * 
+ * \param a extension to compare with b
+ * \param b extension to compare with a
+ *
+ * Checks whether or extension a should match before extension b
+ *
+ * \retval 0 if the two extensions have equal matching priority
+ * \retval 1 on a > b
+ * \retval -1 on a < b
+ */
+int ast_extension_cmp(const char *a, const char *b);
+
+/*! 
  * \brief Launch a new extension (i.e. new stack)
  * 
  * \param c not important

Modified: trunk/main/pbx.c
URL: http://svn.digium.com/view/asterisk/trunk/main/pbx.c?view=diff&rev=88250&r1=88249&r2=88250
==============================================================================
--- trunk/main/pbx.c (original)
+++ trunk/main/pbx.c Fri Nov  2 10:36:34 2007
@@ -804,6 +804,11 @@
 		return 0;
 	else
 		return (ret > 0) ? 1 : -1;
+}
+
+int ast_extension_cmp(const char *a, const char *b)
+{
+	return ext_cmp(a, b);
 }
 
 /*!

Modified: trunk/makeopts.in
URL: http://svn.digium.com/view/asterisk/trunk/makeopts.in?view=diff&rev=88250&r1=88249&r2=88250
==============================================================================
--- trunk/makeopts.in (original)
+++ trunk/makeopts.in Fri Nov  2 10:36:34 2007
@@ -99,6 +99,9 @@
 KDE_INCLUDE=@KDE_INCLUDE@
 KDE_LIB=@KDE_LIB@
 
+LUA_INCLUDE=@LUA_INCLUDE@
+LUA_LIB=@LUA_LIB@
+
 NBS_INCLUDE=@NBS_INCLUDE@
 NBS_LIB=@NBS_LIB@
 

Added: trunk/pbx/pbx_lua.c
URL: http://svn.digium.com/view/asterisk/trunk/pbx/pbx_lua.c?view=auto&rev=88250
==============================================================================
--- trunk/pbx/pbx_lua.c (added)
+++ trunk/pbx/pbx_lua.c Fri Nov  2 10:36:34 2007
@@ -1,0 +1,1290 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 1999 - 2007, Digium, Inc.
+ *
+ * Matthew Nicholson <mnicholson at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! 
+ * \file
+ *
+ * \author Matthew Nicholson <mnicholson at digium.com>
+ * \brief Lua PBX Switch
+ *
+ */
+
+/*** MODULEINFO
+	<depend>lua</depend>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#include "asterisk/logger.h"
+#include "asterisk/channel.h"
+#include "asterisk/pbx.h"
+#include "asterisk/module.h"
+#include "asterisk/cli.h"
+#include "asterisk/utils.h"
+#include "asterisk/term.h"
+
+#include <lua.h>
+#include <lauxlib.h>
+#include <lualib.h>
+
+static char *config = "extensions.lua";
+
+#define LUA_EXT_DATA_SIZE 256
+#define LUA_BUF_SIZE 4096
+
+static char *lua_read_extensions_file(lua_State *L, long *size);
+static int lua_load_extensions(lua_State *L, struct ast_channel *chan);
+static int lua_reload_extensions(lua_State *L);
+static void lua_free_extensions(void);
+static int lua_sort_extensions(lua_State *L);
+static int lua_extension_cmp(lua_State *L);
+static int lua_find_extension(lua_State *L, const char *context, const char *exten, int priority, ast_switch_f *func, int push_func);
+static int lua_pbx_findapp(lua_State *L);
+static int lua_pbx_exec(lua_State *L);
+
+static int lua_get_variable_value(lua_State *L);
+static int lua_set_variable_value(lua_State *L);
+static int lua_get_variable(lua_State *L);
+static int lua_set_variable(lua_State *L);
+static int lua_func_read(lua_State *L);
+
+static int lua_autoservice_start(lua_State *L);
+static int lua_autoservice_stop(lua_State *L);
+static int lua_autoservice_status(lua_State *L);
+
+static void lua_update_registry(lua_State *L, const char *context, const char *exten, int priority);
+static void lua_push_variable_table(lua_State *L, const char *name);
+static void lua_create_app_table(lua_State *L);
+static void lua_create_channel_table(lua_State *L);
+static void lua_create_variable_metatable(lua_State *L);
+static void lua_create_application_metatable(lua_State *L);
+static void lua_create_autoservice_functions(lua_State *L);
+
+void lua_state_destroy(void *data);
+static lua_State *lua_get_state(struct ast_channel *chan);
+
+static int exists(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data);
+static int canmatch(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data);
+static int matchmore(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data);
+static int exec(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data);
+
+AST_MUTEX_DEFINE_STATIC(config_file_lock);
+char *config_file_data = NULL;
+long config_file_size = 0;
+
+static const struct ast_datastore_info lua_datastore = {
+	.type = "lua",
+	.destroy = lua_state_destroy,
+};
+
+
+/*!
+ * \brief The destructor for lua_datastore
+ */
+void lua_state_destroy(void *data)
+{
+	if (data)
+		lua_close(data);
+}
+
+/*!
+ * \brief [lua_CFunction] Find an app and return it in a lua table (for access from lua, don't
+ * call directly)
+ *
+ * This function would be called in the following example as it would be found
+ * in extensions.lua.
+ *
+ * \code
+ * app.dial
+ * \endcode
+ */
+static int lua_pbx_findapp(lua_State *L)
+{
+	const char *app_name = luaL_checkstring(L, 2);
+	
+	lua_newtable(L);
+
+	lua_pushstring(L, "name");
+	lua_pushstring(L, app_name);
+	lua_settable(L, -3);
+
+	luaL_getmetatable(L, "application");
+	lua_setmetatable(L, -2);
+
+	return 1;
+}
+
+/*!
+ * \brief [lua_CFunction] This function is part of the 'application' metatable
+ * and is used to execute applications similar to pbx_exec() (for access from
+ * lua, don't call directly)
+ *
+ * \param L the lua_State to use
+ * \return nothing
+ *
+ * This funciton is executed as the '()' operator for apps accessed through the
+ * 'app' table.
+ *
+ * \code
+ * app.playback('demo-congrats')
+ * \endcode
+ */
+static int lua_pbx_exec(lua_State *L)
+{
+	int nargs = lua_gettop(L);
+	char data[LUA_EXT_DATA_SIZE] = "";
+	char *data_next = data;
+	size_t data_left = sizeof(data);
+	int res;
+	
+	lua_getfield(L, 1, "name");
+	char *app_name = ast_strdupa(lua_tostring(L, -1));
+	lua_pop(L, 1);
+	
+	struct ast_app *app = pbx_findapp(app_name);
+	if (!app) {
+		lua_pushstring(L, "application '");
+		lua_pushstring(L, app_name);
+		lua_pushstring(L, "' not found");
+		lua_concat(L, 3);
+		return lua_error(L);
+	}
+	
+
+	lua_getfield(L, LUA_REGISTRYINDEX, "channel");
+	struct ast_channel *chan = lua_touserdata(L, -1);
+	lua_pop(L, 1);
+	
+	
+	lua_getfield(L, LUA_REGISTRYINDEX, "context");
+	char *context = ast_strdupa(lua_tostring(L, -1));
+	lua_pop(L, 1);
+	
+	lua_getfield(L, LUA_REGISTRYINDEX, "exten");
+	char *exten = ast_strdupa(lua_tostring(L, -1));
+	lua_pop(L, 1);
+	
+	lua_getfield(L, LUA_REGISTRYINDEX, "priority");
+	int priority = lua_tointeger(L, -1);
+	lua_pop(L, 1);
+
+
+	if (nargs > 1) {
+		if (!lua_isnil(L, 2))
+			ast_build_string(&data_next, &data_left, "%s", luaL_checkstring(L, 2));
+
+		int i;
+		for (i = 3; i <= nargs; i++) {
+			if (lua_isnil(L, i))
+				ast_build_string(&data_next, &data_left, ",");
+			else
+				ast_build_string(&data_next, &data_left, ",%s", luaL_checkstring(L, i));
+		}
+	}
+	
+	char tmp[80], tmp2[80], tmp3[LUA_EXT_DATA_SIZE];
+	ast_verb(3, "Executing [%s@%s:%d] %s(\"%s\", \"%s\")\n",
+			exten, context, priority,
+			term_color(tmp, app_name, COLOR_BRCYAN, 0, sizeof(tmp)),
+			term_color(tmp2, chan->name, COLOR_BRMAGENTA, 0, sizeof(tmp2)),
+			term_color(tmp3, data, COLOR_BRMAGENTA, 0, sizeof(tmp3)));
+
+	lua_getfield(L, LUA_REGISTRYINDEX, "autoservice");
+	int autoservice = lua_toboolean(L, -1);
+	lua_pop(L, 1);
+
+	if (autoservice)
+		ast_autoservice_stop(chan);
+
+	res = pbx_exec(chan, app, data);
+	
+	if (autoservice)
+		ast_autoservice_start(chan);
+
+	/* error executing an application, report it */
+	if (res) {
+		lua_pushinteger(L, res);
+		return lua_error(L);
+	}
+	return 0;
+}
+
+/*!
+ * \brief [lua_CFunction] Used to get the value of a variable or dialplan
+ * function (for access from lua, don't call directly)
+ * 
+ * The value of the variable or function is returned.  This function is the
+ * 'get()' function in the following example as would be seen in
+ * extensions.lua.
+ *
+ * \code
+ * channel.variable:get()
+ * \endcode
+ */
+static int lua_get_variable_value(lua_State *L)
+{
+	char *value = NULL;
+	char *workspace = alloca(LUA_BUF_SIZE);
+	workspace[0] = '\0';
+
+	if (!lua_istable(L, 1)) {
+		lua_pushstring(L, "User probably used '.' instead of ':' for retrieving a channel variable value");
+		return lua_error(L);
+	}
+	
+	lua_getfield(L, LUA_REGISTRYINDEX, "channel");
+	struct ast_channel *chan = lua_touserdata(L, -1);
+	lua_pop(L, 1);
+
+	lua_getfield(L, 1, "name");
+	char *name = ast_strdupa(lua_tostring(L, -1));
+	lua_pop(L, 1);
+	
+	lua_getfield(L, LUA_REGISTRYINDEX, "autoservice");
+	int autoservice = lua_toboolean(L, -1);
+	lua_pop(L, 1);
+
+	if (autoservice)
+		ast_autoservice_stop(chan);
+	
+	/* if this is a dialplan function then use ast_func_read(), otherwise
+	 * use pbx_retrieve_variable() */
+	if (!ast_strlen_zero(name) && name[strlen(name) - 1] == ')') {
+		value = ast_func_read(chan, name, workspace, LUA_BUF_SIZE) ? NULL : workspace;
+	} else {
+		pbx_retrieve_variable(chan, name, &value, workspace, LUA_BUF_SIZE, &chan->varshead);
+	}
+	
+	if (autoservice)
+		ast_autoservice_start(chan);
+
+	if (value) {
+		lua_pushstring(L, value);
+	} else {
+		lua_pushnil(L);
+	}
+
+	return 1;
+}
+
+/*!
+ * \brief [lua_CFunction] Used to set the value of a variable or dialplan
+ * function (for access from lua, don't call directly)
+ * 
+ * This function is the 'set()' function in the following example as would be
+ * seen in extensions.lua.
+ *
+ * \code
+ * channel.variable:set()
+ * \endcode
+ */
+static int lua_set_variable_value(lua_State *L)
+{
+	if (!lua_istable(L, 1)) {
+		lua_pushstring(L, "User probably used '.' instead of ':' for setting a channel variable");
+		return lua_error(L);
+	}
+
+	lua_getfield(L, 1, "name");
+	const char *name = ast_strdupa(lua_tostring(L, -1));
+	lua_pop(L, 1);
+
+	const char *value = luaL_checkstring(L, 2);
+	
+	lua_getfield(L, LUA_REGISTRYINDEX, "channel");
+	struct ast_channel *chan = lua_touserdata(L, -1);
+	lua_pop(L, 1);
+
+	lua_getfield(L, LUA_REGISTRYINDEX, "autoservice");
+	int autoservice = lua_toboolean(L, -1);
+	lua_pop(L, 1);
+
+	if (autoservice)
+		ast_autoservice_stop(chan);
+
+	pbx_builtin_setvar_helper(chan, name, value);
+	
+	if (autoservice)
+		ast_autoservice_start(chan);
+
+	return 0;
+}
+
+/*!
+ * \brief Update the lua registry with the given context, exten, and priority.
+ *
+ * \param L the lua_State to use
+ * \param context the new context
+ * \param exten the new exten
+ * \param priority the new priority
+ */
+static void lua_update_registry(lua_State *L, const char *context, const char *exten, int priority)
+{
+	lua_pushstring(L, context);
+	lua_setfield(L, LUA_REGISTRYINDEX, "context");
+
+	lua_pushstring(L, exten);
+	lua_setfield(L, LUA_REGISTRYINDEX, "exten");
+
+	lua_pushinteger(L, priority);
+	lua_setfield(L, LUA_REGISTRYINDEX, "priority");
+}
+
+/*!
+ * \brief Push a 'variable' table on the stack for access the channel variable
+ * with the given name.
+ *
+ * \param L the lua_State to use
+ * \param name the name of the variable
+ */
+static void lua_push_variable_table(lua_State *L, const char *name)
+{
+	lua_newtable(L);
+	luaL_getmetatable(L, "variable");
+	lua_setmetatable(L, -2);
+
+	lua_pushstring(L, name);
+	lua_setfield(L, -2, "name");
+	
+	lua_pushcfunction(L, &lua_get_variable_value);
+	lua_setfield(L, -2, "get");
+	
+	lua_pushcfunction(L, &lua_set_variable_value);
+	lua_setfield(L, -2, "set");
+}
+
+/*!
+ * \brief Create the global 'app' table for executing applications
+ *

[... 1027 lines stripped ...]



More information about the asterisk-commits mailing list