Lua class implementation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.