The code below, uses the lua, socket.http library to pull a web page (for simplicity I have used a link to a text file). I have used tex.sprint to pass it back to the typesetting engine. However I would have preferred to print within a verbatim environment or preferably using the listings environment. Any suggestions as to how I can achieve this?
\documentclass{article}
\usepackage[utf8]{luainputenc}
\begin{document}
\bgroup
\catcode`\%=12
\catcode`\_=12
\catcode`\^=12
\catcode`\&=12
\directlua{
local http = require("socket.http")
function url_encode(str)
if (str) then
str = string.gsub (str, "\string\n", "\string\r\string\n")
str = string.gsub (str, "([^%w ])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
end
return str
end
function url_decode(str)
str = string.gsub (str, "+", " ")
str = string.gsub (str, "%%(%x%x)",
function(h) return string.char(tonumber(h,16)) end)
str = string.gsub (str, "\string\n", "\string\n")
return str
end
local page = http.request( 'http://mirror-cybernet.lums.edu.pk/pub/ctan/dviware/screenview/vms/test.txt' )
tex.sprint(page)
}
\egroup
\end{document}
Note, the MWE contains two functions that I haven't used, for encoding and decoding the url. I left them in case you want to try a different url. As a sideline I find it amazing that old 'TeX' in new clothes can talk to the web.