Line | |
---|
1 | function printf(...) io.write(string.format(unpack(arg))) end |
---|
2 | |
---|
3 | function Account:show() |
---|
4 | printf("Account balance = $%0.02f\n", self:balance()) |
---|
5 | end |
---|
6 | |
---|
7 | a = Account(100) |
---|
8 | b = Account:new(30) |
---|
9 | |
---|
10 | print('a =', a) |
---|
11 | print('b =', b) |
---|
12 | print('metatable =', getmetatable(a)) |
---|
13 | print('Account =', Account) |
---|
14 | table.foreach(Account, print) |
---|
15 | |
---|
16 | a:show() a:deposit(50.30) a:show() a:withdraw(25.10) a:show() |
---|
17 | |
---|
18 | parent = {} |
---|
19 | |
---|
20 | function parent:rob(amount) |
---|
21 | amount = amount or self:balance() |
---|
22 | self:withdraw(amount) |
---|
23 | return amount |
---|
24 | end |
---|
25 | |
---|
26 | getmetatable(Account).__index = parent |
---|
27 | |
---|
28 | debug.debug() |
---|
Note: See
TracBrowser
for help on using the repository browser.