I just read the "object-oriented programming" chapter in the latest Lua book. I think Lua handles this poorly. Lua's use of ":" for objected-oriented access is confusing and I left it out of Luan. I don't think most Luan users should do object-oriented programming, but if they do, they should do it like this:
function newAccount(initialBalance)
local self = {}
local balance = initialBalance or 0
function self.withdraw(v)
balance = balance - v
end
function self.deposit(v)
balance = balance + v
end
function self.getBalance()
return balance
end
return self
end
acct = newAccount(100.00)
acct.withdraw(40.00)
print(acct.getBalance())
This is how I would implement the example given in the Lua book.