comparison http/src/luan/modules/http/run.luan @ 503:92c3d22745b8

make _ENV optional
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 20 May 2015 23:24:46 -0600
parents ee55be414a34
children 7bc63886d4f2
comparison
equal deleted inserted replaced
502:d3183a330ff5 503:92c3d22745b8
4 local Io = require "luan:Io" 4 local Io = require "luan:Io"
5 local print = Io.print 5 local print = Io.print
6 local Http = require "luan:http/Http" 6 local Http = require "luan:http/Http"
7 local String = require "luan:String" 7 local String = require "luan:String"
8 local Html = require "luan:Html" 8 local Html = require "luan:Html"
9
10 local M = {}
9 11
10 local function lines(s) 12 local function lines(s)
11 local matcher = s.gmatch "([^\n]*)\n|([^\n])+$" 13 local matcher = s.gmatch "([^\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
17 19
18 local function print_with_line_numbers(s) 20 local function print_with_line_numbers(s)
19 i = 1 21 local i = 1
20 for line in lines(s) do 22 for line in lines(s) do
21 print(i,line) 23 print(i,line)
22 i = i + 1 24 i = i + 1
23 end 25 end
24 end 26 end
45 <% Html.simply_html_body_bottom() %> 47 <% Html.simply_html_body_bottom() %>
46 </body> 48 </body>
47 </html> 49 </html>
48 <% end 50 <% end
49 51
50 function respond() 52 function M.respond()
51 Io.stdout = Http.response.text_writer() 53 Io.stdout = Http.response.text_writer()
52 local code = Http.request.parameter.code 54 local code = Http.request.parameter.code
53 if code == nil then 55 if code == nil then
54 form() 56 form()
55 return 57 return
74 print() 76 print()
75 print_with_line_numbers(code) 77 print_with_line_numbers(code)
76 end; 78 end;
77 } 79 }
78 end 80 end
81
82 return M