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