Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pch/src/tolua/lua/enumerate.lua @ 3129

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

Update to tolua 1.0.93

  • Property svn:eol-style set to native
File size: 2.8 KB
Line 
1-- tolua: enumerate class
2-- Written by Waldemar Celes
3-- TeCGraf/PUC-Rio
4-- Jul 1998
5-- $Id: enumerate.lua,v 1.3 2000/01/24 20:41:15 celes Exp $
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-- Enumerate class
14-- Represents enumeration
15-- The following fields are stored:
16--    {i} = list of constant names
17classEnumerate = {
18}
19classEnumerate.__index = classEnumerate
20setmetatable(classEnumerate,classFeature)
21
22-- register enumeration
23function classEnumerate:register (pre)
24    if not self:check_public_access() then
25        return
26    end
27    pre = pre or ''
28    local nspace = getnamespace(classContainer.curr)
29    local i=1
30    while self[i] do
31        if self.lnames[i] and self.lnames[i] ~= "" then
32            output(pre..'tolua_constant(tolua_S,"'..self.lnames[i]..'",'..nspace..self[i]..');')
33        end
34        i = i+1
35    end
36end
37
38-- Print method
39function classEnumerate:print (ident,close)
40    print(ident.."Enumerate{")
41    print(ident.." name = "..self.name)
42    local i=1
43    while self[i] do
44        print(ident.." '"..self[i].."'("..self.lnames[i].."),")
45        i = i+1
46    end
47    print(ident.."}"..close)
48end
49
50-- Internal constructor
51function _Enumerate (t,varname)
52    setmetatable(t,classEnumerate)
53    append(t)
54    appendenum(t)
55    if varname and varname ~= "" then
56        if t.name ~= "" then
57            Variable(t.name.." "..varname)
58        else
59            local ns = getcurrnamespace()
60            warning("Variable "..ns..varname.." of type <anonymous enum> is declared as read-only")
61            Variable("tolua_readonly int "..varname)
62        end
63    end
64    local parent = classContainer.curr
65    if parent then
66        t.access = parent.curr_member_access
67        t.global_access = t:check_public_access()
68    end
69    return t
70end
71
72-- Constructor
73-- Expects a string representing the enumerate body
74function Enumerate (n,b,varname)
75    b = string.gsub(b, ",[%s\n]*}", "\n}") -- eliminate last ','
76    local t = split(strsub(b,2,-2),',') -- eliminate braces
77    local i = 1
78    local e = {n=0}
79    while t[i] do
80        local tt = split(t[i],'=')  -- discard initial value
81        e.n = e.n + 1
82        e[e.n] = tt[1]
83        i = i+1
84    end
85    -- set lua names
86    i  = 1
87    e.lnames = {}
88    local ns = getcurrnamespace()
89    while e[i] do
90        local t = split(e[i],'@')
91        e[i] = t[1]
92        if not t[2] then
93            t[2] = applyrenaming(t[1])
94        end
95        e.lnames[i] = t[2] or t[1]
96        _global_enums[ ns..e[i] ] = (ns..e[i])
97        i = i+1
98    end
99    e.name = n
100    if n ~= "" then
101        Typedef("int "..n)
102    end
103    return _Enumerate(e, varname)
104end
105
Note: See TracBrowser for help on using the repository browser.