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

try statement
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 21 Jun 2020 18:14:13 -0600
parents 9eba6bf0163b
children fa066aaa068c
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 try = Luan.try or error()
5 local Io = require "luan:Io.luan" 4 local Io = require "luan:Io.luan"
6 local print = Io.print or error() 5 local print = Io.print or error()
7 local String = require "luan:String.luan" 6 local String = require "luan:String.luan"
8 local gmatch = String.gmatch or error() 7 local gmatch = String.gmatch or error()
9 local Http = require "luan:http/Http.luan" 8 local Http = require "luan:http/Http.luan"
66 </body> 65 </body>
67 </html> 66 </html>
68 <% end 67 <% end
69 68
70 function Run.run(code,source_name) 69 function Run.run(code,source_name)
71 return try { 70 try
72 function() 71 local run = load(code,source_name)
73 local run = load(code,source_name) 72 run()
74 run() 73 return true
75 return true 74 catch e
76 end 75 Http.response.reset()
77 catch = function(e) 76 Http.response.headers["content-type"] = "text/plain; charset=utf-8"
78 Http.response.reset() 77 Io.stdout = Http.response.text_writer()
79 Http.response.headers["content-type"] = "text/plain; charset=utf-8" 78 print(e)
80 Io.stdout = Http.response.text_writer() 79 print()
81 print(e) 80 print()
82 print() 81 print_with_line_numbers(code)
83 print() 82 return false
84 print_with_line_numbers(code) 83 end
85 return false
86 end
87 }
88 end 84 end
89 85
90 function Run.respond() 86 function Run.respond()
91 local content_type = Http.request.parameters.content_type 87 local content_type = Http.request.parameters.content_type
92 if content_type ~= nil then 88 if content_type ~= nil then