Here is a simple example of lua object-oriented implementation.
Acount = {balance = 0, withdraw = function (self, v) self. balance = self. balance-vend} function Acount: deposit (v) self. balance = self. balance + vendfunction Acount: new (o) -- make it impossible for o to be empty, it is a table o = o or {} -- Here self is Acount itself, then, the meta table of table o is acountsetretriable (o, self) -- _ index pointing to the Account itself. When the new object (that is, the table) cannot find the element, it will be found in the Account table. Self. _ index = selfreturn oenda = Acount: new ({balance = 0}) B = Acount: new {balance = 55} -- here a calls the deposit method, but cannot find it, so you can find it in its meta table -- equivalent to: gemetatable (). _ index. deposit (a, 1000) a: deposit (1000) B: deposit (1000) print (. balance) print (B. balance)