Last change
on this file since 8105 was
8061,
checked in by bensch, 18 years ago
|
merged the scriptengine back to the trunk
|
File size:
629 bytes
|
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 | |
---|
8 | o = Object() |
---|
9 | o:printName() |
---|
10 | |
---|
11 | Obj:printName() --external added object |
---|
12 | |
---|
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 | |
---|
24 | |
---|
25 | |
---|
26 | parent = {} |
---|
27 | function parent:rob(amount) |
---|
28 | amount = amount or self:balance() |
---|
29 | self:withdraw(amount) |
---|
30 | return amount |
---|
31 | end |
---|
32 | |
---|
33 | getmetatable(Account).__index = parent |
---|
34 | |
---|
35 | --debug.debug() |
---|
Note: See
TracBrowser
for help on using the repository browser.