OOP in Lua
OOP in Lua is different than that in C++. In C++, you define a class and create instances of the class. The classes defined are unique types at the language level.
In Lua, there is no native class concept. OOP in Lua is prototype-based. This is more like JavaScript if you are familiar with it. For a Lua table, if an entry is not present, you can instruct Lua to check another table for it, which acts as the prototype for the table you are explicitly referencing.
For ease of understanding, it’s fine to call this prototype table the “class” and the table the “object”. Or, you can call the relationship “inheritance.” Although prototype and class are two different object-oriented (OO) methodologies, sometimes people use the two terms interchangeably.
Let’s write a class that we will use to learn how to call Lua table functions. Suppose we want to keep a list of places we want to go and note whether we have visited...