Rev | Line | |
---|
[8046] | 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 | parent = {} |
---|
| 8 | |
---|
| 9 | function parent:rob(amount) |
---|
| 10 | amount = amount or self:balance() |
---|
| 11 | self:withdraw(amount) |
---|
| 12 | return amount |
---|
| 13 | end |
---|
| 14 | |
---|
| 15 | getmetatable(Account).__index = parent |
---|
| 16 | |
---|
[8271] | 17 | |
---|
| 18 | function test() |
---|
| 19 | io.write("Hi i'm test\n") |
---|
| 20 | end |
---|
| 21 | |
---|
| 22 | |
---|
[8046] | 23 | function main(arg) |
---|
[8408] | 24 | io.write("hello i am main!") |
---|
[8271] | 25 | -- use parameter |
---|
[8046] | 26 | io.write("main received ", arg) |
---|
| 27 | io.write(" as parameter\n") |
---|
[8271] | 28 | |
---|
[8408] | 29 | o = Object() |
---|
| 30 | o:printName() |
---|
[8271] | 31 | --call member of an inserted object |
---|
[8046] | 32 | Obj:printName() |
---|
[8271] | 33 | |
---|
| 34 | --create object of a registered type |
---|
[8408] | 35 | --o = Object() |
---|
| 36 | --o:printName() |
---|
[8271] | 37 | |
---|
| 38 | --take returnvalue from c |
---|
| 39 | callCount = Obj:getCallCount() |
---|
| 40 | io.write("callCount is now ",callCount) |
---|
| 41 | io.write("\n") |
---|
| 42 | |
---|
| 43 | --pass parameters to a c++ method |
---|
| 44 | Obj:takeParam(3) |
---|
| 45 | |
---|
| 46 | --print object information |
---|
[8046] | 47 | print('a =', a) |
---|
| 48 | print('b =', b) |
---|
| 49 | print('metatable =', getmetatable(a)) |
---|
| 50 | print('Account =', Account) |
---|
| 51 | table.foreach(Account, print) |
---|
| 52 | |
---|
| 53 | a:show() a:deposit(50.30) a:show() a:withdraw(25.10) a:show() |
---|
| 54 | Obj:printName() |
---|
[8058] | 55 | |
---|
[8271] | 56 | return 2,false,2.72 |
---|
| 57 | |
---|
[8046] | 58 | --debug.debug() |
---|
| 59 | end |
---|
Note: See
TracBrowser
for help on using the repository browser.