Mercurial Hosting > luan
changeset 495:598123096772
rename service() to respond()
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 15 May 2015 18:10:14 -0600 |
parents | 2b9bc97f0439 |
children | c65df5b25932 |
files | http/src/luan/modules/http/Http.luan http/src/luan/modules/http/HttpServicer.java http/src/luan/modules/http/run.luan http/src/luan/modules/http/shell.luan lucene/src/luan/modules/lucene/Ab_testing.luan scripts/test.luan website/src/diff.html.luan website/src/docs.html.luan website/src/examples/hi.luan website/src/examples/hi2.luan website/src/examples/hi2_simply_html.luan website/src/index.html.luan website/src/manual.html.luan website/src/pil.html.luan website/src/tutorial.html.luan |
diffstat | 15 files changed, 24 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/http/src/luan/modules/http/Http.luan Fri May 15 17:43:13 2015 -0600 +++ b/http/src/luan/modules/http/Http.luan Fri May 15 18:10:14 2015 -0600 @@ -13,7 +13,7 @@ end local old_out = Io.stdout local mod = require("site:"..path) - mod.service() + mod.respond() text_writer.close() Io.stdout = old_out return result.read_text()
--- a/http/src/luan/modules/http/HttpServicer.java Fri May 15 17:43:13 2015 -0600 +++ b/http/src/luan/modules/http/HttpServicer.java Fri May 15 18:10:14 2015 -0600 @@ -95,12 +95,12 @@ private static LuanFunction getService(LuanState luan,LuanTable tbl) throws LuanException { - Object service = tbl.get(luan,"service"); - if( service == null ) - throw luan.exception( "function 'service' is not defined" ); - if( !(service instanceof LuanFunction) ) - throw luan.exception( "'service' must be a function but is a " + Luan.type(service) ); - return (LuanFunction)service; + Object respond = tbl.get(luan,"respond"); + if( respond == null ) + throw luan.exception( "function 'respond' is not defined" ); + if( !(respond instanceof LuanFunction) ) + throw luan.exception( "'respond' must be a function but is a " + Luan.type(respond) ); + return (LuanFunction)respond; }
--- a/http/src/luan/modules/http/run.luan Fri May 15 17:43:13 2015 -0600 +++ b/http/src/luan/modules/http/run.luan Fri May 15 18:10:14 2015 -0600 @@ -47,7 +47,7 @@ </html> <% end -function service() +function respond() Io.stdout = Http.response.text_writer() local code = Http.request.parameters.code if code == nil then
--- a/http/src/luan/modules/http/shell.luan Fri May 15 17:43:13 2015 -0600 +++ b/http/src/luan/modules/http/shell.luan Fri May 15 18:10:14 2015 -0600 @@ -13,7 +13,7 @@ local history = {} env = {} -function service() +function respond() if Http.request.parameters.clear ~= nil then history = {} else
--- a/lucene/src/luan/modules/lucene/Ab_testing.luan Fri May 15 17:43:13 2015 -0600 +++ b/lucene/src/luan/modules/lucene/Ab_testing.luan Fri May 15 18:10:14 2015 -0600 @@ -132,7 +132,7 @@ end function ab_testing.web_page(test_names) - return { service = function() + return { respond = function() local results = {} for _, name in ipairs(test_names) do local test = ab_testing.test_map[name]
--- a/scripts/test.luan Fri May 15 17:43:13 2015 -0600 +++ b/scripts/test.luan Fri May 15 18:10:14 2015 -0600 @@ -11,8 +11,8 @@ Io.print_to(Io.stderr,...) end -function Io.schemes.site(path) - return Io.uri( "luan:http"..path ) +function Io.schemes.site(path,add_extension) + return Io.uri( "luan:http"..path, add_extension ) end @@ -51,7 +51,7 @@ end Http.init_for_test() -ab_testing.web_page{"All","null"}.service() +ab_testing.web_page{"All","null"}.respond() print "done"
--- a/website/src/diff.html.luan Fri May 15 17:43:13 2015 -0600 +++ b/website/src/diff.html.luan Fri May 15 18:10:14 2015 -0600 @@ -6,7 +6,7 @@ heading_options = Manual.heading_options -function service() +function respond() Io.stdout = Http.response.text_writer() %> <html>
--- a/website/src/docs.html.luan Fri May 15 17:43:13 2015 -0600 +++ b/website/src/docs.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>
--- a/website/src/examples/hi.luan Fri May 15 17:43:13 2015 -0600 +++ b/website/src/examples/hi.luan Fri May 15 18:10:14 2015 -0600 @@ -2,7 +2,7 @@ local Http = require "luan:http/Http" -function service() +function respond() Io.stdout = Http.response.text_writer() %> <html>
--- a/website/src/examples/hi2.luan Fri May 15 17:43:13 2015 -0600 +++ b/website/src/examples/hi2.luan Fri May 15 18:10:14 2015 -0600 @@ -28,7 +28,7 @@ <% end -function service() +function respond() Io.stdout = Http.response.text_writer() name = Http.request.parameters.name if name == nil then
--- a/website/src/examples/hi2_simply_html.luan Fri May 15 17:43:13 2015 -0600 +++ b/website/src/examples/hi2_simply_html.luan Fri May 15 18:10:14 2015 -0600 @@ -17,7 +17,7 @@ <% end -function service() +function respond() Io.stdout = Http.response.text_writer() name = Http.request.parameters.name %>
--- a/website/src/index.html.luan Fri May 15 17:43:13 2015 -0600 +++ b/website/src/index.html.luan Fri May 15 18:10:14 2015 -0600 @@ -3,7 +3,7 @@ local Http = require "luan:http/Http" -function service() +function respond() Io.stdout = Http.response.text_writer() %> <html>
--- a/website/src/manual.html.luan Fri May 15 17:43:13 2015 -0600 +++ b/website/src/manual.html.luan Fri May 15 18:10:14 2015 -0600 @@ -6,7 +6,7 @@ heading_options = [[margin-top="2em" margin-bottom=".6em" textcolor="#233E93"]] -function service() +function respond() Io.stdout = Http.response.text_writer() %> <html>
--- a/website/src/pil.html.luan Fri May 15 17:43:13 2015 -0600 +++ b/website/src/pil.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>
--- 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>