1 | -- tolua: module class |
---|
2 | -- Written by Waldemar Celes |
---|
3 | -- TeCGraf/PUC-Rio |
---|
4 | -- Jul 1998 |
---|
5 | -- $Id: $ |
---|
6 | |
---|
7 | -- This code is free software; you can redistribute it and/or modify it. |
---|
8 | -- The software provided hereunder is on an "as is" basis, and |
---|
9 | -- the author has no obligation to provide maintenance, support, updates, |
---|
10 | -- enhancements, or modifications. |
---|
11 | |
---|
12 | |
---|
13 | |
---|
14 | -- Module class |
---|
15 | -- Represents module. |
---|
16 | -- The following fields are stored: |
---|
17 | -- {i} = list of objects in the module. |
---|
18 | classModule = { |
---|
19 | classtype = 'module' |
---|
20 | } |
---|
21 | classModule.__index = classModule |
---|
22 | setmetatable(classModule,classContainer) |
---|
23 | |
---|
24 | -- register module |
---|
25 | function classModule:register (pre) |
---|
26 | pre = pre or '' |
---|
27 | push(self) |
---|
28 | output(pre..'tolua_module(tolua_S,"'..self.name..'",',self:hasvar(),');') |
---|
29 | output(pre..'tolua_beginmodule(tolua_S,"'..self.name..'");') |
---|
30 | local i=1 |
---|
31 | while self[i] do |
---|
32 | self[i]:register(pre..' ') |
---|
33 | i = i+1 |
---|
34 | end |
---|
35 | output(pre..'tolua_endmodule(tolua_S);') |
---|
36 | pop() |
---|
37 | end |
---|
38 | |
---|
39 | -- Print method |
---|
40 | function classModule:print (ident,close) |
---|
41 | print(ident.."Module{") |
---|
42 | print(ident.." name = '"..self.name.."';") |
---|
43 | local i=1 |
---|
44 | while self[i] do |
---|
45 | self[i]:print(ident.." ",",") |
---|
46 | i = i+1 |
---|
47 | end |
---|
48 | print(ident.."}"..close) |
---|
49 | end |
---|
50 | |
---|
51 | -- Internal constructor |
---|
52 | function _Module (t) |
---|
53 | setmetatable(t,classModule) |
---|
54 | append(t) |
---|
55 | return t |
---|
56 | end |
---|
57 | |
---|
58 | -- Constructor |
---|
59 | -- Expects two string representing the module name and body. |
---|
60 | function Module (n,b) |
---|
61 | local t = _Module(_Container{name=n}) |
---|
62 | push(t) |
---|
63 | t:parse(strsub(b,2,strlen(b)-1)) -- eliminate braces |
---|
64 | pop() |
---|
65 | return t |
---|
66 | end |
---|
67 | |
---|
68 | |
---|