summaryrefslogtreecommitdiffstats
path: root/lib/tolua++/src/bin/lua/namespace.lua
blob: 6ca80e6e34e59d1dee61bafe9392dde8f1d6ff67 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
-- tolua: namespace class
-- Written by Waldemar Celes
-- TeCGraf/PUC-Rio
-- Jul 2003
-- $Id: $

-- This code is free software; you can redistribute it and/or modify it.
-- The software provided hereunder is on an "as is" basis, and
-- the author has no obligation to provide maintenance, support, updates,
-- enhancements, or modifications.


-- Namespace class
-- Represents a namesapce definition.
-- Stores the following fields:
--    name = class name
--    {i}  = list of members
classNamespace = {
 classtype = 'namespace',
 name = '',
}
classNamespace.__index = classNamespace
setmetatable(classNamespace,classModule)

-- Print method
function classNamespace:print (ident,close)
 print(ident.."Namespace{")
 print(ident.." name = '"..self.name.."',")
 local i=1
 while self[i] do
  self[i]:print(ident.." ",",")
  i = i+1
 end
 print(ident.."}"..close)
end

-- Internal constructor
function _Namespace (t)
 setmetatable(t,classNamespace)
 append(t)
 return t
end

-- Constructor
-- Expects the name and the body of the namespace.
function Namespace (n,b)
 local c = _Namespace(_Container{name=n})
 push(c)
 c:parse(strsub(b,2,strlen(b)-1)) -- eliminate braces
 pop()
end