Mercurial Hosting > luan
diff website/src/tutorial.html.luan @ 495:598123096772
rename service() to respond()
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 15 May 2015 18:10:14 -0600 |
parents | 2b9bc97f0439 |
children | 92c3d22745b8 |
line wrap: on
line diff
--- a/website/src/tutorial.html.luan Fri May 15 17:43:13 2015 -0600 +++ b/website/src/tutorial.html.luan Fri May 15 18:10:14 2015 -0600 @@ -4,7 +4,7 @@ local Shared = require "site:/Shared" -function service() +function respond() Io.stdout = Http.response.text_writer() %> <html> @@ -74,7 +74,7 @@ local Io = require "luan:Io" local Http = require "luan:http/Http" - function service() + function respond() Io.stdout = Http.response.text_writer() %> <html> @@ -88,7 +88,7 @@ <p>Now go back to the parent directory and do <b>luan luan:http/serve file:site</b>. This will run the Luan web server on port 8080. Try going to <a href="http://localhost:8080/">http://localhost:8080/</a>. You should see the directory. If you click on <b>hi.luan</b> you will see the source. But if you remove the <b>.luan</b> and just go to <a href="http://localhost:8080/hi">http://localhost:8080/hi</a> then you will run the program which will generate the web page.</p> -<p>The Luan webserver looks for function named <b>service</b> in the file and calls it to generate the page. Code of the form <b><%=Html.encode[[%>...<%]]%></b> writes its output to <b>Io.stdout</b> which by default is the standard output of the command line. So in <b>service</b> one usually starts by setting <b>Io.stdout</b> to a <tt>text_writer</tt> which writes its output to the HTTP response (to the web browser).</p> +<p>The Luan webserver looks for function named <b>respond</b> in the file and calls it to generate the page. Code of the form <b><%=Html.encode[[%>...<%]]%></b> writes its output to <b>Io.stdout</b> which by default is the standard output of the command line. So in <b>respond</b> one usually starts by setting <b>Io.stdout</b> to a <tt>text_writer</tt> which writes its output to the HTTP response (to the web browser).</p> <p>You can find this example and others in the <a href="examples">examples directory</a>. Take a look at <a href="examples/hi2.luan">hi2.luan</a> next. Remember to remove the <b>.luan</b> from the URL to run the code. And by the way, you can see the source for this page at <a href="tutorial.html.luan">tutorial.html.luan</a>.</p>