1--	Part of FusionPBX
2--	Copyright (C) 2013 Mark J Crane <markjcrane@fusionpbx.com>
3--	All rights reserved.
4--
5--	Redistribution and use in source and binary forms, with or without
6--	modification, are permitted provided that the following conditions are met:
7--
8--	1. Redistributions of source code must retain the above copyright notice,
9--	  this list of conditions and the following disclaimer.
10--
11--	2. Redistributions in binary form must reproduce the above copyright
12--	  notice, this list of conditions and the following disclaimer in the
13--	  documentation and/or other materials provided with the distribution.
14--
15--	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16--	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17--	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
18--	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
19--	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20--	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21--	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22--	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23--	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24--	POSSIBILITY OF SUCH DAMAGE.
25
26
27--include config.lua
28	require "resources.functions.config";
29
30--get the argv values
31	script_name = argv[0];
32	app_name = argv[1];
33
34--example use command
35	--luarun app.lua app_name 'a' 'b 123' 'c'
36
37--for loop through arguments
38	arguments = "";
39	for key,value in pairs(argv) do
40		if (key > 1) then
41			arguments = arguments .. " '" .. value .. "'";
42			--freeswitch.consoleLog("notice", "[app.lua] argv["..key.."]: "..argv[key].."\n");
43		end
44	end
45
46--route the request to the application
47	--freeswitch.consoleLog("notice", "["..app_name.."]".. scripts_dir .. "/app/" .. app_name .. "/index.lua\n");
48	loadfile(scripts_dir .. "/app/" .. app_name .. "/index.lua")(argv);
49