Mercurial Hosting > luan
comparison http/src/luan/modules/http/run.luan @ 580:1e69d9c21461
add Table.clear();
add Http.response.reset();
fix http/run;
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 21 Jul 2015 14:56:41 -0600 |
parents | 2f39468680be |
children | ca169567ce07 |
comparison
equal
deleted
inserted
replaced
579:f22a09e98b04 | 580:1e69d9c21461 |
---|---|
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() | 4 local try = Luan.try or error() |
5 local Io = require "luan:Io" | 5 local Io = require "luan:Io" |
6 local print = Io.print or error() | 6 local print = Io.print or error() |
7 local String = require "luan:String" | |
8 local gmatch = String.gmatch or error() | |
7 local Http = require "luan:http/Http" | 9 local Http = require "luan:http/Http" |
8 | 10 |
9 | 11 |
10 local function lines(s) | 12 local function lines(s) |
11 local matcher = s.gmatch "([^\n]*)\n|([^\n])+$" | 13 local matcher = gmatch(s,"([^\n]*)\n|([^\n])+$") |
12 return function() | 14 return function() |
13 local m1, m2 = matcher() | 15 local m1, m2 = matcher() |
14 return m1 or m2 | 16 return m1 or m2 |
15 end | 17 end |
16 end | 18 end |
70 </body> | 72 </body> |
71 </html> | 73 </html> |
72 <% end | 74 <% end |
73 | 75 |
74 return function() | 76 return function() |
77 local content_type = Http.request.parameter.content_type | |
78 if content_type ~= nil then | |
79 Http.response.header.content_type = content_type | |
80 end | |
75 Io.stdout = Http.response.text_writer() | 81 Io.stdout = Http.response.text_writer() |
76 local code = Http.request.parameter.code | 82 local code = Http.request.parameter.code |
77 if code == nil then | 83 if code == nil then |
78 form() | 84 form() |
79 return | 85 return |
80 end | |
81 local content_type = Http.request.parameter.content_type | |
82 if content_type ~= nil then | |
83 Http.response.header.content_type = content_type | |
84 end | 86 end |
85 local env = { | 87 local env = { |
86 request = Http.request; | 88 request = Http.request; |
87 response = Http.response; | 89 response = Http.response; |
88 } | 90 } |
90 function() | 92 function() |
91 local run = load(code,"<web_run>",env) | 93 local run = load(code,"<web_run>",env) |
92 run() | 94 run() |
93 end; | 95 end; |
94 catch = function(e) | 96 catch = function(e) |
97 Http.response.reset() | |
95 Http.response.header.content_type = "text/plain" | 98 Http.response.header.content_type = "text/plain" |
99 Io.stdout = Http.response.text_writer() | |
96 print(e) | 100 print(e) |
97 print() | 101 print"" |
98 print() | 102 print"" |
99 print_with_line_numbers(code) | 103 print_with_line_numbers(code) |
100 end; | 104 end; |
101 } | 105 } |
102 end | 106 end |