Main Content

A fresh example - objects the Lua way

Archive - Originally posted on "The Horse's Mouth" - 2009-08-13 14:45:14 - Graham Ellis

One of the requirements we often have in our web server log file analyses is to connect together a series of accesses from a single IP address into a "visit", and this formed an example on Tuesday's Lua course.

In Lua, you can overload (i.e. redefine) operators so that they work differently on tables of different types, and in this case I chose to redefine addition so that it concatenates two visits, allowing all the access log records from a single source to be logically grouped even though there are many different visitors (i.e. IP addresses) coming to our site at the same time:

(This diagram shows you just how wide ranging our visitors are - it's dynamic, showing you the last 15 minutes up to when you loaded the page!)

The log file analysis program comes several days into our Lua Programming course so it's not practical for me to document every line here, but if you already know Lua, you're more than welcome to look at the calling code here and the object definition here. The latter contains a good block of comments!