Mercurial Hosting > luan
comparison website/src/tutorial.html.luan @ 512:d96944467ffc
update documentation for luan changes
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 22 May 2015 16:08:23 -0600 |
parents | 7bc63886d4f2 |
children | 7cc9d4a53d3b |
comparison
equal
deleted
inserted
replaced
511:e3fb9768dbb3 | 512:d96944467ffc |
---|---|
57 | 57 |
58 <p><tt><pre> | 58 <p><tt><pre> |
59 local Io = require "luan:Io" | 59 local Io = require "luan:Io" |
60 local print = Io.print | 60 local print = Io.print |
61 | 61 |
62 function hello(name) | 62 local function hello(name) |
63 print("Hello "..name) | 63 print("Hello "..name) |
64 end | 64 end |
65 | 65 |
66 hello("Bob") | 66 hello("Bob") |
67 </pre></tt></p> | 67 </pre></tt></p> |
72 | 72 |
73 <p><tt><pre><%=Html.encode[[ | 73 <p><tt><pre><%=Html.encode[[ |
74 local Io = require "luan:Io" | 74 local Io = require "luan:Io" |
75 local Http = require "luan:http/Http" | 75 local Http = require "luan:http/Http" |
76 | 76 |
77 function respond() | 77 return function() |
78 Io.stdout = Http.response.text_writer() | 78 Io.stdout = Http.response.text_writer() |
79 %> | 79 %> |
80 <html> | 80 <html> |
81 <body> | 81 <body> |
82 Hello World | 82 Hello World |
86 end | 86 end |
87 ]]%></pre></tt></p> | 87 ]]%></pre></tt></p> |
88 | 88 |
89 <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> | 89 <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> |
90 | 90 |
91 <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> | 91 <p>The Luan webserver expects the file to return a function 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 the returned function 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> |
92 | 92 |
93 <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> | 93 <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> |
94 | 94 |
95 <p>So now you have built your website and you want to publish it to the web. If you have your own domain, create a CNAME record for it pointing to <b>s1.luanhost.com</b>. If you don't have a domain, just use a domain like <b>bob.s1.luanhost.com</b> (anything of the form <b>*.s1.luanhost.com</b>). Assuming your directory is <b>site</b> and you will use the password <b>secret</b>, do the following from the command line: | 95 <p>So now you have built your website and you want to publish it to the web. If you have your own domain, create a CNAME record for it pointing to <b>s1.luanhost.com</b>. If you don't have a domain, just use a domain like <b>bob.s1.luanhost.com</b> (anything of the form <b>*.s1.luanhost.com</b>). Assuming your directory is <b>site</b> and you will use the password <b>secret</b>, do the following from the command line: |
96 | 96 |