1 _account= {}2 3 --Create a debit card4 function _account: New (TB)5 Local _TB= TBor {}6 _TB._mbalance=_TB._mbalance or 07 setmetatable(_TB, self)8Self.__index = Self9 return _TBTen End One A --Debit Card Withdrawals - function _account:d esposit (value) - ifValue > Self._mbalance Then the Print("Insufficient funds!") - return - End -Self._mbalance= self._mbalance-value + Print(String.Format("You Get%s money! ", value)) - End + A --Save at function _account: Addbalance (val) - Localnum = valor 0 -Self._mbalance= self._mbalance+Num - End - - LocalMyaccount_2 =myaccount:new () inMyaccount_2:addbalance ( +) -Myaccount_2:desposit ( $) to + ------------------------------------------------------- - _credit=_account: New ({_mlimit= +}) the * --Credit card Withdrawals $ function _credit:d esposit (value)Panax Notoginseng ifValue > Self._mbalance+ Self._mlimit Then - Print("Insufficient funds!") the return + End ASelf._mbalance= self._mbalance-value the Print(String.Format("You get:%s money", value)) + End - $ LocalCycredit =_credit: New () $Cycredit:desposit ( -)
Lua class implementation