fork download
  1. Account={money=0, last_change=0}
  2. function Account:deposit(summ)
  3. self.money=self.money+summ
  4. self.last_change=summ
  5. end
  6. function Account:withdraw(summ)
  7. self.money=self.money-summ
  8. self.last_change=0-summ
  9. end
  10. function Account:status()
  11. print('Money: '..self.money)
  12. print('Last change: '..self.last_change)
  13. end
  14. function Account.new(money)
  15. return {money=money, last_change=0, withdraw=Account.withdraw, deposit=Account.deposit, status=Account.status}
  16. end
  17. acc=Account.new(0)
  18. acc:status()
  19. print('"acc.deposit(190)')
  20. acc:deposit(190)
  21. acc:status()
  22. print('"acc.withdraw(110)')
  23. acc:withdraw(110)
  24. acc:status()
Success #stdin #stdout 0.01s 2540KB
stdin
Standard input is empty
stdout
Money: 0
Last change: 0
"acc.deposit(190)
Money: 190
Last change: 190
"acc.withdraw(110)
Money: 80
Last change: -110