comparison src/luan/modules/http/tools/Shell.luan @ 1520:d9a5405a3102

try statement
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 21 Jun 2020 18:14:13 -0600
parents 1604d7f36f3a
children d3e61cd2aca0
comparison
equal deleted inserted replaced
1519:3ebf9781707c 1520:d9a5405a3102
1 local Luan = require "luan:Luan.luan" 1 local Luan = require "luan:Luan.luan"
2 local error = Luan.error 2 local error = Luan.error
3 local load = Luan.load or error() 3 local load = Luan.load or error()
4 local to_string = Luan.to_string or error() 4 local to_string = Luan.to_string or error()
5 local try = Luan.try or error()
6 local range = Luan.range or error() 5 local range = Luan.range or error()
7 local Table = require "luan:Table.luan" 6 local Table = require "luan:Table.luan"
8 local concat = Table.concat or error() 7 local concat = Table.concat or error()
9 local pack = Table.pack or error() 8 local pack = Table.pack or error()
10 local unpack = Table.unpack or error() 9 local unpack = Table.unpack or error()
31 Shell.env = env 30 Shell.env = env
32 31
33 local fns = {} 32 local fns = {}
34 33
35 function fns.run(cmd) 34 function fns.run(cmd)
36 return try { 35 try
37 function() 36 try
38 local line 37 return load("return "..cmd,"<web_shell>",env)
39 try { 38 catch e
40 function() 39 return load(cmd,"<web_shell>",env)
41 line = load("return "..cmd,"<web_shell>",env)
42 end
43 catch = function(e)
44 line = load(cmd,"<web_shell>",env)
45 end
46 }
47 return line()
48 end 40 end
49 catch = function(e) 41 catch e
50 -- Io.print_to(Io.stderr,e) 42 -- Io.print_to(Io.stderr,e)
51 return to_string(e) 43 return to_string(e)
52 end 44 end
53 }
54 end 45 end
55 46
56 local timeout = Time.period{hours=10} 47 local timeout = Time.period{hours=10}
57 48
58 local function get_session(session_id) 49 local function get_session(session_id)