Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 14, 2009, 10:53:45 PM (15 years ago)
Author:
rgrieder
Message:

Merged buildsystem2 to buildsystem3.

Note: Bare merge, just resolved conflicts. To testing, no nothing.

Location:
code/branches/buildsystem3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/buildsystem3

  • code/branches/buildsystem3/src/tolua/lua/operator.lua

    r2087 r2664  
    1616--  kind = set of character representing the operator (as it appers in C++ code)
    1717classOperator = {
    18  kind = '',
     18    kind = '',
    1919}
    2020classOperator.__index = classOperator
     
    2222
    2323-- table to transform operator kind into the appropriate tag method name
    24 _TM = {['+'] = 'add',
    25        ['-'] = 'sub',
    26        ['*'] = 'mul',
    27        ['/'] = 'div',
    28        ['<'] = 'lt',
    29        ['<='] = 'le',
    30        ['=='] = 'eq',
    31        ['[]'] = 'geti',
    32        ['&[]'] = 'seti',
    33        --['->'] = 'flechita',
    34       }
     24_TM = {
     25    ['+'] = 'add',
     26    ['-'] = 'sub',
     27    ['*'] = 'mul',
     28    ['/'] = 'div',
     29    ['<'] = 'lt',
     30    ['<='] = 'le',
     31    ['=='] = 'eq',
     32    ['[]'] = 'geti',
     33    ['&[]'] = 'seti',
     34    --['->'] = 'flechita',
     35}
    3536
    3637
    3738-- Print method
    3839function classOperator:print (ident,close)
    39  print(ident.."Operator{")
    40  print(ident.." kind  = '"..self.kind.."',")
    41  print(ident.." mod  = '"..self.mod.."',")
    42  print(ident.." type = '"..self.type.."',")
    43  print(ident.." ptr  = '"..self.ptr.."',")
    44  print(ident.." name = '"..self.name.."',")
    45  print(ident.." const = '"..self.const.."',")
    46  print(ident.." cname = '"..self.cname.."',")
    47  print(ident.." lname = '"..self.lname.."',")
    48  print(ident.." args = {")
    49  local i=1
    50  while self.args[i] do
    51   self.args[i]:print(ident.."  ",",")
    52   i = i+1
    53  end
    54  print(ident.." }")
    55  print(ident.."}"..close)
     40    print(ident.."Operator{")
     41    print(ident.." kind  = '"..self.kind.."',")
     42    print(ident.." mod  = '"..self.mod.."',")
     43    print(ident.." type = '"..self.type.."',")
     44    print(ident.." ptr  = '"..self.ptr.."',")
     45    print(ident.." name = '"..self.name.."',")
     46    print(ident.." const = '"..self.const.."',")
     47    print(ident.." cname = '"..self.cname.."',")
     48    print(ident.." lname = '"..self.lname.."',")
     49    print(ident.." args = {")
     50    local i=1
     51    while self.args[i] do
     52        self.args[i]:print(ident.."  ",",")
     53        i = i+1
     54    end
     55    print(ident.." }")
     56    print(ident.."}"..close)
    5657end
    5758
    5859function classOperator:supcode_tmp()
    5960
    60         if not _TM[self.kind] then
    61                 return classFunction.supcode(self)
    62         end
    63 
    64         -- no overload, no parameters, always inclass
    65         output("/* method:",self.name," of class ",self:inclass()," */")
    66 
    67         output("#ifndef TOLUA_DISABLE_"..self.cname)
    68         output("\nstatic int",self.cname,"(lua_State* tolua_S)")
    69 
    70         if overload < 0 then
    71         output('#ifndef TOLUA_RELEASE\n')
    72         end
    73         output(' tolua_Error tolua_err;')
    74         output(' if (\n')
    75         -- check self
    76         output('     !'..'tolua_isusertype(tolua_S,1,"'..self.parent.type..'",0,&tolua_err) ||\n')
    77         output('     !tolua_isnoobj(tolua_S,2,&tolua_err)\n )')
    78         output('  goto tolua_lerror;')
    79 
    80         output(' else\n')
    81         output('#endif\n') -- tolua_release
    82         output(' {')
    83 
    84         -- declare self
    85         output(' ',self.const,self.parent.type,'*','self = ')
    86         output('(',self.const,self.parent.type,'*) ')
    87         output('tolua_tousertype(tolua_S,1,0);')
    88 
    89         -- check self
    90         output('#ifndef TOLUA_RELEASE\n')
    91         output('  if (!self) tolua_error(tolua_S,"invalid \'self\' in function \''..self.name..'\'",NULL);');
    92         output('#endif\n')
    93 
    94         -- cast self
    95         output('  ',self.mod,self.type,self.ptr,'tolua_ret = ')
    96         output('(',self.mod,self.type,self.ptr,')(*self);')
    97 
    98         -- return value
    99         local t,ct = isbasic(self.type)
    100         if t then
    101                 output('   tolua_push'..t..'(tolua_S,(',ct,')tolua_ret);')
    102         else
    103                 t = self.type
    104                 new_t = string.gsub(t, "const%s+", "")
    105                 if self.ptr == '' then
    106                         output('   {')
    107                         output('#ifdef __cplusplus\n')
    108                         output('    void* tolua_obj = new',new_t,'(tolua_ret);')
    109                         output('    tolua_pushusertype_and_takeownership(tolua_S,tolua_obj,"',t,'");')
    110                         output('#else\n')
    111                         output('    void* tolua_obj = tolua_copy(tolua_S,(void*)&tolua_ret,sizeof(',t,'));')
    112                         output('    tolua_pushusertype_and_takeownership(tolua_S,tolua_obj,"',t,'");')
    113                         output('#endif\n')
    114                         output('   }')
    115                 elseif self.ptr == '&' then
    116                         output('   tolua_pushusertype(tolua_S,(void*)&tolua_ret,"',t,'");')
    117                 else
    118                         if local_constructor then
    119                                 output('   tolua_pushusertype_and_takeownership(tolua_S,(void *)tolua_ret,"',t,'");')
    120                         else
    121                                 output('   tolua_pushusertype(tolua_S,(void*)tolua_ret,"',t,'");')
    122                         end
    123                 end
    124         end
    125 
    126         output('  }')
    127         output(' return 1;')
    128 
    129         output('#ifndef TOLUA_RELEASE\n')
    130         output('tolua_lerror:\n')
    131         output(' tolua_error(tolua_S,"#ferror in function \''..self.lname..'\'.",&tolua_err);')
    132         output(' return 0;')
    133         output('#endif\n')
    134 
    135 
    136         output('}')
    137         output('#endif //#ifndef TOLUA_DISABLE\n')
    138         output('\n')
     61    if not _TM[self.kind] then
     62        return classFunction.supcode(self)
     63    end
     64
     65    -- no overload, no parameters, always inclass
     66    output("/* method:",self.name," of class ",self:inclass()," */")
     67
     68    output("#ifndef TOLUA_DISABLE_"..self.cname)
     69    output("\nstatic int",self.cname,"(lua_State* tolua_S)")
     70
     71    if overload < 0 then
     72        output('#ifndef TOLUA_RELEASE\n')
     73    end
     74    output(' tolua_Error tolua_err;')
     75    output(' if (\n')
     76    -- check self
     77    output('     !'..'tolua_isusertype(tolua_S,1,"'..self.parent.type..'",0,&tolua_err) ||\n')
     78    output('     !tolua_isnoobj(tolua_S,2,&tolua_err)\n )')
     79    output('  goto tolua_lerror;')
     80
     81    output(' else\n')
     82    output('#endif\n') -- tolua_release
     83    output(' {')
     84
     85    -- declare self
     86    output(' ',self.const,self.parent.type,'*','self = ')
     87    output('(',self.const,self.parent.type,'*) ')
     88    output('tolua_tousertype(tolua_S,1,0);')
     89
     90    -- check self
     91    output('#ifndef TOLUA_RELEASE\n')
     92    output('  if (!self) tolua_error(tolua_S,"invalid \'self\' in function \''..self.name..'\'",NULL);');
     93    output('#endif\n')
     94
     95    -- cast self
     96    output('  ',self.mod,self.type,self.ptr,'tolua_ret = ')
     97    output('(',self.mod,self.type,self.ptr,')(*self);')
     98
     99    -- return value
     100    local t,ct = isbasic(self.type)
     101    if t then
     102        output('   tolua_push'..t..'(tolua_S,(',ct,')tolua_ret);')
     103    else
     104        t = self.type
     105        new_t = string.gsub(t, "const%s+", "")
     106        if self.ptr == '' then
     107            output('   {')
     108            output('#ifdef __cplusplus\n')
     109            output('    void* tolua_obj = new',new_t,'(tolua_ret);')
     110            output('    tolua_pushusertype_and_takeownership(tolua_S,tolua_obj,"',t,'");')
     111            output('#else\n')
     112            output('    void* tolua_obj = tolua_copy(tolua_S,(void*)&tolua_ret,sizeof(',t,'));')
     113            output('    tolua_pushusertype_and_takeownership(tolua_S,tolua_obj,"',t,'");')
     114            output('#endif\n')
     115            output('   }')
     116        elseif self.ptr == '&' then
     117            output('   tolua_pushusertype(tolua_S,(void*)&tolua_ret,"',t,'");')
     118        else
     119            if local_constructor then
     120                output('   tolua_pushusertype_and_takeownership(tolua_S,(void *)tolua_ret,"',t,'");')
     121            else
     122                output('   tolua_pushusertype(tolua_S,(void*)tolua_ret,"',t,'");')
     123            end
     124        end
     125    end
     126
     127    output('  }')
     128    output(' return 1;')
     129
     130    output('#ifndef TOLUA_RELEASE\n')
     131    output('tolua_lerror:\n')
     132    output(' tolua_error(tolua_S,"#ferror in function \''..self.lname..'\'.",&tolua_err);')
     133    output(' return 0;')
     134    output('#endif\n')
     135
     136
     137    output('}')
     138    output('#endif //#ifndef TOLUA_DISABLE\n')
     139    output('\n')
    139140end
    140141
    141142-- Internal constructor
    142143function _Operator (t)
    143  setmetatable(t,classOperator)
    144 
    145  if t.const ~= 'const' and t.const ~= '' then
    146   error("#invalid 'const' specification")
    147  end
    148 
    149  append(t)
    150  if not t:inclass() then
    151   error("#operator can only be defined as class member")
    152  end
    153 
    154  --t.name = t.name .. "_" .. (_TM[t.kind] or t.kind)
    155  t.cname = t:cfuncname("tolua")..t:overload(t)
    156  t.name = "operator" .. t.kind  -- set appropriate calling name
    157  return t
     144    setmetatable(t,classOperator)
     145
     146    if t.const ~= 'const' and t.const ~= '' then
     147        error("#invalid 'const' specification")
     148    end
     149
     150    append(t)
     151    if not t:inclass() then
     152        error("#operator can only be defined as class member")
     153    end
     154
     155    --t.name = t.name .. "_" .. (_TM[t.kind] or t.kind)
     156    t.cname = t:cfuncname("tolua")..t:overload(t)
     157    t.name = "operator" .. t.kind  -- set appropriate calling name
     158    return t
    158159end
    159160
     
    161162function Operator (d,k,a,c)
    162163
    163         local op_k = string.gsub(k, "^%s*", "")
    164         op_k = string.gsub(k, "%s*$", "")
    165         --if string.find(k, "^[%w_:%d<>%*%&]+$") then
    166         if d == "operator" and k ~= '' then
    167 
    168                 d = k.." operator"
    169         elseif not _TM[op_k] then
    170 
    171                 if flags['W'] then
    172                         error("tolua: no support for operator" .. f.kind)
    173                 else
    174                         warning("No support for operator "..op_k..", ignoring")
    175                         return nil
    176                 end
    177         end
    178 
    179         local ref = ''
    180  local t = split_c_tokens(strsub(a,2,strlen(a)-1),',') -- eliminate braces
    181  local i=1
    182  local l = {n=0}
    183  while t[i] do
    184   l.n = l.n+1
    185   l[l.n] = Declaration(t[i],'var')
    186   i = i+1
    187  end
    188  if k == '[]' then
    189         local _
    190         _, _, ref = strfind(d,'(&)')
    191   d = gsub(d,'&','')
    192  elseif k=='&[]' then
    193   l.n = l.n+1
    194   l[l.n] = Declaration(d,'var')
    195   l[l.n].name = 'tolua_value'
    196  end
    197  local f = Declaration(d,'func')
    198  if k == '[]' and (l[1]==nil or isbasic(l[1].type)~='number') then
    199   error('operator[] can only be defined for numeric index.')
    200  end
    201  f.args = l
    202  f.const = c
    203  f.kind = op_k
    204  f.lname = "."..(_TM[f.kind] or f.kind)
    205  if not _TM[f.kind] then
    206         f.cast_operator = true
    207  end
    208  if f.kind == '[]' and ref=='&' and f.const~='const' then
    209   Operator(d,'&'..k,a,c)        -- create correspoding set operator
    210  end
    211  return _Operator(f)
    212 end
    213 
    214 
     164    local op_k = string.gsub(k, "^%s*", "")
     165    op_k = string.gsub(k, "%s*$", "")
     166    --if string.find(k, "^[%w_:%d<>%*%&]+$") then
     167    if d == "operator" and k ~= '' then
     168
     169        d = k.." operator"
     170    elseif not _TM[op_k] then
     171
     172        if flags['W'] then
     173            error("tolua: no support for operator" .. f.kind)
     174        else
     175            warning("No support for operator "..op_k..", ignoring")
     176            return nil
     177        end
     178    end
     179
     180    local ref = ''
     181    local t = split_c_tokens(strsub(a,2,strlen(a)-1),',') -- eliminate braces
     182    local i=1
     183    local l = {n=0}
     184    while t[i] do
     185        l.n = l.n+1
     186        l[l.n] = Declaration(t[i],'var')
     187        i = i+1
     188    end
     189    if k == '[]' then
     190        local _
     191        _, _, ref = strfind(d,'(&)')
     192        d = gsub(d,'&','')
     193    elseif k=='&[]' then
     194        l.n = l.n+1
     195        l[l.n] = Declaration(d,'var')
     196        l[l.n].name = 'tolua_value'
     197    end
     198    local f = Declaration(d,'func')
     199    if k == '[]' and (l[1]==nil or isbasic(l[1].type)~='number') then
     200        error('operator[] can only be defined for numeric index.')
     201    end
     202    f.args = l
     203    f.const = c
     204    f.kind = op_k
     205    f.lname = "."..(_TM[f.kind] or f.kind)
     206    if not _TM[f.kind] then
     207        f.cast_operator = true
     208    end
     209    if f.kind == '[]' and ref=='&' and f.const~='const' then
     210        Operator(d,'&'..k,a,c)     -- create correspoding set operator
     211    end
     212    return _Operator(f)
     213end
     214
     215
Note: See TracChangeset for help on using the changeset viewer.