Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy/src/tolua/lua/module.lua @ 2041

Last change on this file since 2041 was 2040, checked in by rgrieder, 16 years ago

reverted those svn:eol-style "native" properties: Tomorrow then.

File size: 1.5 KB
Line 
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.
18classModule = {
19 classtype = 'module'
20}
21classModule.__index = classModule
22setmetatable(classModule,classContainer)
23
24-- register module
25function 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()
37end
38
39-- Print method
40function 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)
49end
50
51-- Internal constructor
52function _Module (t)
53 setmetatable(t,classModule)
54 append(t)
55 return t
56end
57
58-- Constructor
59-- Expects two string representing the module name and body.
60function 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
66end
67
68
Note: See TracBrowser for help on using the repository browser.