HTTP package

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

HTTP package

fschmidt
Administrator
I thought this through more and now I have a clear idea how to do it.  I want to modify the existing web package to make the http package so I can do it incrementally and make sure everything keeps working.  In the end, it will be totally different than it is now.  I think you will be shocked how simple HTTP can be.  Please assign this back to me before the end of the sabbath and I will work on this.  Once I start working on it, you shouldn't update your Luan until I have things stable.
Woe to those who call bad good and good bad -- Isaiah 5:20
Following the Old Testament, not evil modern culture
Reply | Threaded
Open this post in threaded view
|

Re: HTTP package

Hugo <Nabble>
Sounds good. Just go ahead.
Reply | Threaded
Open this post in threaded view
|

Re: HTTP package

fschmidt
Administrator
Removing _ENV, Hello World becomes:
local Io = require "luan:Io"
local Http = require "luan:http/Http"

local M = {}

function M.respond()
	Io.stdout = Http.response.text_writer()
	%>
	<html>
		<body>
			Hello World
		</body>
	</html>
	<%
end

return M
An alternative would be to have pages return a function like this:
local Io = require "luan:Io"
local Http = require "luan:http/Http"

return function()
	Io.stdout = Http.response.text_writer()
	%>
	<html>
		<body>
			Hello World
		</body>
	</html>
	<%
end
What do you think?
Woe to those who call bad good and good bad -- Isaiah 5:20
Following the Old Testament, not evil modern culture
Reply | Threaded
Open this post in threaded view
|

Re: HTTP package

Hugo <Nabble>
fschmidt wrote
Removing _ENV, Hello World becomes:
local Io = require "luan:Io"
local Http = require "luan:http/Http"

local M = {}

function M.respond()
	Io.stdout = Http.response.text_writer()
	%>
	<html>
		<body>
			Hello World
		</body>
	</html>
	<%
end

return M
I would rather use the word "this" instead of "M". Is the word "this" possible or reserved in this case?
fschmidt wrote
An alternative would be to have pages return a function like this:
local Io = require "luan:Io"
local Http = require "luan:http/Http"

return function()
	Io.stdout = Http.response.text_writer()
	%>
	<html>
		<body>
			Hello World
		</body>
	</html>
	<%
end
What do you think?
Okay, but I think it is better to keep modules consistent and have functions assigned to a local table that is returned at the end.
Reply | Threaded
Open this post in threaded view
|

Re: HTTP package

fschmidt
Administrator
Hugo <Nabble> wrote
I would rather use the word "this" instead of "M". Is the word "this" possible or reserved in this case?
You can use any word, but "M" is the Lua convention.  See the Programming in Lua book or http://lua-users.org/wiki/ModuleDefinition .

Okay, but I think it is better to keep modules consistent and have functions assigned to a local table that is returned at the end.
Pages are not library modules, they are something else.  The Lua module concept allows returning any object.  We can discuss this later.
Woe to those who call bad good and good bad -- Isaiah 5:20
Following the Old Testament, not evil modern culture
Reply | Threaded
Open this post in threaded view
|

Re: HTTP package

Hugo <Nabble>
We discussed this. Returning the function is certainly better.
Reply | Threaded
Open this post in threaded view
|

Re: HTTP package

fschmidt
Administrator
done in rev 7bc63886d4f2

I will keep this to update other projects for this.
Woe to those who call bad good and good bad -- Isaiah 5:20
Following the Old Testament, not evil modern culture
Reply | Threaded
Open this post in threaded view
|

Re: HTTP package

fschmidt
Administrator
In reply to this post by Hugo <Nabble>
This is stable now, closing.
Woe to those who call bad good and good bad -- Isaiah 5:20
Following the Old Testament, not evil modern culture