Last change
on this file since 8349 was
8061,
checked in by bensch, 19 years ago
|
merged the scriptengine back to the trunk
|
File size:
629 bytes
|
Rev | Line | |
---|
[7821] | 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 | |
---|
[8044] | 7 | |
---|
[7975] | 8 | o = Object() |
---|
| 9 | o:printName() |
---|
[7962] | 10 | |
---|
[8021] | 11 | Obj:printName() --external added object |
---|
[7975] | 12 | |
---|
[7821] | 13 | a = Account(100) |
---|
| 14 | b = Account:new(30) |
---|
| 15 | |
---|
| 16 | print('a =', a) |
---|
| 17 | print('b =', b) |
---|
| 18 | print('metatable =', getmetatable(a)) |
---|
| 19 | print('Account =', Account) |
---|
| 20 | table.foreach(Account, print) |
---|
| 21 | |
---|
| 22 | a:show() a:deposit(50.30) a:show() a:withdraw(25.10) a:show() |
---|
| 23 | |
---|
[8044] | 24 | |
---|
| 25 | |
---|
[7821] | 26 | parent = {} |
---|
[8044] | 27 | function parent:rob(amount) |
---|
[7821] | 28 | amount = amount or self:balance() |
---|
| 29 | self:withdraw(amount) |
---|
| 30 | return amount |
---|
| 31 | end |
---|
| 32 | |
---|
| 33 | getmetatable(Account).__index = parent |
---|
| 34 | |
---|
[7829] | 35 | --debug.debug() |
---|
Note: See
TracBrowser
for help on using the repository browser.