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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
-- tolua: class class
-- Written by Waldemar Celes
-- TeCGraf/PUC-Rio
-- Jul 1998
-- $Id: class.lua,v 1.2 2001/11/26 23:00:23 darkgod Exp $
-- 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.
-- Class class
-- Represents a class definition.
-- Stores the following fields:
-- name = class name
-- base = class base, if any (only single inheritance is supported)
-- {i} = list of members
classClass = {
_base = classContainer,
type = 'class',
name = '',
base = '',
}
settag(classClass,tolua_tag)
-- register class
function classClass:register ()
output(' tolua_cclass(tolua_S,"'..self.name..'","'..self.base..'");')
local i=1
while self[i] do
self[i]:register()
i = i+1
end
end
-- unregister class
function classClass:unregister ()
output(' lua_pushnil(tolua_S); lua_setglobal(tolua_S,"'..self.name..'");')
end
-- output tags
function classClass:decltag ()
self.itype,self.tag = tagvar(self.name);
self.citype,self.ctag = tagvar(self.name,'const');
local i=1
while self[i] do
self[i]:decltag()
i = i+1
end
end
-- Print method
function classClass:print (ident,close)
print(ident.."Class{")
print(ident.." name = '"..self.name.."',")
print(ident.." base = '"..self.base.."';")
local i=1
while self[i] do
self[i]:print(ident.." ",",")
i = i+1
end
print(ident.."}"..close)
end
-- Internal constructor
function _Class (t)
t._base = classClass
settag(t,tolua_tag)
append(t)
return t
end
-- Constructor
-- Expects the name, the base and the body of the class.
function Class (n,p,b)
local c = _Class(_Container{name=n, base=p})
push(c)
c:parse(strsub(b,2,strlen(b)-1)) -- eliminate braces
pop()
end
|