Tables as Objects in Lua - a gentle introduction to data driven programming
Archive - Originally posted on "The Horse's Mouth" - 2011-08-17 21:33:04 - Graham Ellis
In Lua, everything that's a collection is held in a table. During the Lua Course I have been giving this week, I set up a whole series of tables, object-like, to hold details of each station on the British main rail network. As well as data, the table holds code / code references, and by adding different code to different station tables, the calculations made later can automatically be varied to take account of the type of station that's involved. So that's sub-class like, and polymorphism, in a very clever way.
The source code is [here]. The railstats data file it uses is [here].