STM publishing: tools, technologies and change A WordPress site for STM Publishing

9Oct/11Off

LuaTeX can connect to networks

One feature of LuaTeX which might prove useful in some circumstances is its ability to connect to networks through TCP/IP. This facility is due to the luasocket TCP/IP networking library which is built into the executable. In addition to the low-level TCP/IP facilities, luasocket provides a number of support modules which make the following tasks quite easy to do:

  • HTTP (e.g., web access)
  • SMTP (sending e-mails)
  • FTP (uploading and downloading files)

To use luasocket you need to load the libraries and away you go. Here's a trivial example which makes an HTTP call to a server, stores the server's response in a Lua table and typesets it. To build more advanced examples you'll need to read about the ltn12 module.


\directlua{

local ltn12 = require("ltn12")
local http = require("socket.http")

function grabtext(httplink)
local tab = {}
local res = http.request{url = httplink, sink = ltn12.sink.table(tab)}
return tab
end

local t = grabtext("http://your_url_here")
tex.print(t[1])
}

Vastly more complex examples could be built, of course.

Filed under: Examples Comments Off
Comments (0) Trackbacks (0)

Sorry, the comment form is closed at this time.

No trackbacks yet.