Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pch/src/tolua/lua/feature.lua @ 3127

Last change on this file since 3127 was 3127, checked in by rgrieder, 15 years ago

Update to tolua 1.0.93

  • Property svn:eol-style set to native
File size: 3.1 KB
Line 
1-- tolua: abstract feature 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-- Feature class
14-- Represents the base class of all mapped feature.
15classFeature = {
16}
17classFeature.__index = classFeature
18
19-- write support code
20function classFeature:supcode ()
21end
22
23-- output tag
24function classFeature:decltype ()
25end
26
27-- register feature
28function classFeature:register (pre)
29end
30
31-- translate verbatim
32function classFeature:preamble ()
33end
34
35-- check if it is a variable
36function classFeature:isvariable ()
37 return false
38end
39
40-- check if it requires collection
41function classFeature:requirecollection (t)
42    return false
43end
44
45-- build names
46function classFeature:buildnames ()
47    if self.name and self.name~='' then
48        local n = split(self.name,'@')
49        self.name = n[1]
50        self.name = string.gsub(self.name, ":%d*$", "")
51        if not n[2] then
52            n[2] = applyrenaming(n[1])
53        end
54        self.lname = n[2] or gsub(n[1],"%[.-%]","")
55        self.lname = string.gsub(self.lname, ":%d*$", "")
56        self.original_name = self.name
57        self.lname = clean_template(self.lname)
58    end
59    if not self.is_parameter then
60        self.name = getonlynamespace() .. self.name
61    end
62
63    local parent = classContainer.curr
64    if parent then
65        self.access = parent.curr_member_access
66        self.global_access = self:check_public_access()
67    else
68    end
69end
70
71function classFeature:check_public_access()
72
73    if type(self.global_access) == "boolean" then
74        return self.global_access
75    end
76
77    if self.access and self.access ~= 0 then
78        return false
79    end
80
81    local parent = classContainer.curr
82    while parent do
83        if parent.access and parent.access ~= 0 then
84            return false
85        end
86        parent = parent.prox
87    end
88    return true
89end
90
91function clean_template(t)
92
93    return string.gsub(t, "[<>:, %*]", "_")
94end
95
96-- check if feature is inside a container definition
97-- it returns the container class name or nil.
98function classFeature:incontainer (which)
99    if self.parent then
100        local parent = self.parent
101        while parent do
102            if parent.classtype == which then
103                return parent.name
104            end
105            parent = parent.parent
106        end
107    end
108    return nil
109end
110
111function classFeature:inclass ()
112    return self:incontainer('class')
113end
114
115function classFeature:inmodule ()
116    return self:incontainer('module')
117end
118
119function classFeature:innamespace ()
120    return self:incontainer('namespace')
121end
122
123-- return C binding function name based on name
124-- the client specifies a prefix
125function classFeature:cfuncname (n)
126
127    if self.parent then
128        n = self.parent:cfuncname(n)
129    end
130
131    local fname = self.lname
132    if not fname or fname == '' then
133        fname = self.name
134    end
135    n = string.gsub(n..'_'.. (fname), "[<>:, \.%*&]", "_")
136
137    return n
138end
139
Note: See TracBrowser for help on using the repository browser.