Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 17, 2008, 8:59:48 PM (16 years ago)
Author:
rgrieder
Message:

Merged revisions 1875-2278 of the buildsystem branch to buildsystem2.

Location:
code/branches/buildsystem2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/buildsystem2

  • code/branches/buildsystem2/src/tolua/lua/enumerate.lua

    r2087 r2509  
    2222-- register enumeration
    2323function classEnumerate:register (pre)
    24  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
     24    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
    3131end
    3232
    3333-- Print method
    3434function classEnumerate: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)
     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)
    4343end
    4444
    4545-- Internal constructor
    4646function _Enumerate (t,varname)
    47  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
     47    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
    6060end
    6161
     
    6363-- Expects a string representing the enumerate body
    6464function Enumerate (n,b,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)
     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)
    9494end
    9595
Note: See TracChangeset for help on using the changeset viewer.