Changeset 2509 for code/branches/buildsystem2/src/tolua/lua/enumerate.lua
- Timestamp:
- Dec 17, 2008, 8:59:48 PM (16 years ago)
- Location:
- code/branches/buildsystem2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/buildsystem2
- Property svn:ignore deleted
- Property svn:mergeinfo changed
/code/branches/buildsystem (added) merged: 1875,1882-1886,1975-1982,1991,1999,2054,2061,2135,2137-2139,2197-2199,2204,2214-2220,2223-2224,2229,2233-2244,2248-2249,2252-2253,2260,2275
-
code/branches/buildsystem2/src/tolua/lua/enumerate.lua
r2087 r2509 22 22 -- register enumeration 23 23 function classEnumerate:register (pre) 24 pre = pre or ''25 local nspace = getnamespace(classContainer.curr)26 local i=127 while self[i] do28 output(pre..'tolua_constant(tolua_S,"'..self.lnames[i]..'",'..nspace..self[i]..');')29 i = i+130 end24 pre = pre or '' 25 local nspace = getnamespace(classContainer.curr) 26 local i=1 27 while self[i] do 28 output(pre..'tolua_constant(tolua_S,"'..self.lnames[i]..'",'..nspace..self[i]..');') 29 i = i+1 30 end 31 31 end 32 32 33 33 -- Print method 34 34 function classEnumerate:print (ident,close) 35 print(ident.."Enumerate{")36 print(ident.." name = "..self.name)37 local i=138 while self[i] do39 print(ident.." '"..self[i].."'("..self.lnames[i].."),")40 i = i+141 end42 print(ident.."}"..close)35 print(ident.."Enumerate{") 36 print(ident.." name = "..self.name) 37 local i=1 38 while self[i] do 39 print(ident.." '"..self[i].."'("..self.lnames[i].."),") 40 i = i+1 41 end 42 print(ident.."}"..close) 43 43 end 44 44 45 45 -- Internal constructor 46 46 function _Enumerate (t,varname) 47 setmetatable(t,classEnumerate)48 append(t)49 appendenum(t)50 51 52 53 54 55 56 57 58 59 return t47 setmetatable(t,classEnumerate) 48 append(t) 49 appendenum(t) 50 if varname and varname ~= "" then 51 if t.name ~= "" then 52 Variable(t.name.." "..varname) 53 else 54 local ns = getcurrnamespace() 55 warning("Variable "..ns..varname.." of type <anonymous enum> is declared as read-only") 56 Variable("tolua_readonly int "..varname) 57 end 58 end 59 return t 60 60 end 61 61 … … 63 63 -- Expects a string representing the enumerate body 64 64 function Enumerate (n,b,varname) 65 66 local t = split(strsub(b,2,-2),',') -- eliminate braces67 local i = 168 local e = {n=0}69 while t[i] do70 local tt = split(t[i],'=') -- discard initial value71 e.n = e.n + 172 e[e.n] = tt[1]73 i = i+174 end75 -- set lua names76 i = 177 e.lnames = {}78 local ns = getcurrnamespace()79 while e[i] do80 local t = split(e[i],'@')81 e[i] = t[1]82 83 84 85 e.lnames[i] = t[2] or t[1]86 _global_enums[ ns..e[i] ] = (ns..e[i])87 i = i+188 end89 90 91 92 93 return _Enumerate(e, varname)65 b = string.gsub(b, ",[%s\n]*}", "\n}") -- eliminate last ',' 66 local t = split(strsub(b,2,-2),',') -- eliminate braces 67 local i = 1 68 local e = {n=0} 69 while t[i] do 70 local tt = split(t[i],'=') -- discard initial value 71 e.n = e.n + 1 72 e[e.n] = tt[1] 73 i = i+1 74 end 75 -- set lua names 76 i = 1 77 e.lnames = {} 78 local ns = getcurrnamespace() 79 while e[i] do 80 local t = split(e[i],'@') 81 e[i] = t[1] 82 if not t[2] then 83 t[2] = applyrenaming(t[1]) 84 end 85 e.lnames[i] = t[2] or t[1] 86 _global_enums[ ns..e[i] ] = (ns..e[i]) 87 i = i+1 88 end 89 e.name = n 90 if n ~= "" then 91 Typedef("int "..n) 92 end 93 return _Enumerate(e, varname) 94 94 end 95 95
Note: See TracChangeset
for help on using the changeset viewer.