Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 19, 2008, 4:40:43 PM (15 years ago)
Author:
rgrieder
Message:

Cleaned up indentation chaos in tolua. There were tabs and 1 space indentations, even mixed in a single block.
It should now be possible to actually pimp these files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/buildsystem/src/tolua/lua/array.lua

    r1755 r2229  
    2121-- Print method
    2222function classArray:print (ident,close)
    23  print(ident.."Array{")
    24  print(ident.." mod  = '"..self.mod.."',")
    25  print(ident.." type = '"..self.type.."',")
    26  print(ident.." ptr  = '"..self.ptr.."',")
    27  print(ident.." name = '"..self.name.."',")
    28  print(ident.." def  = '"..self.def.."',")
    29  print(ident.." dim  = '"..self.dim.."',")
    30  print(ident.." ret  = '"..self.ret.."',")
    31  print(ident.."}"..close)
     23    print(ident.."Array{")
     24    print(ident.." mod  = '"..self.mod.."',")
     25    print(ident.." type = '"..self.type.."',")
     26    print(ident.." ptr  = '"..self.ptr.."',")
     27    print(ident.." name = '"..self.name.."',")
     28    print(ident.." def  = '"..self.def.."',")
     29    print(ident.." dim  = '"..self.dim.."',")
     30    print(ident.." ret  = '"..self.ret.."',")
     31    print(ident.."}"..close)
    3232end
    3333
    3434-- check if it is a variable
    3535function classArray:isvariable ()
    36  return true
     36    return true
    3737end
    3838
     
    4040-- get variable value
    4141function classArray:getvalue (class,static)
    42  if class and static then
    43   return class..'::'..self.name..'[tolua_index]'
    44  elseif class then
    45   return 'self->'..self.name..'[tolua_index]'
    46  else
    47   return self.name..'[tolua_index]'
    48  end
     42    if class and static then
     43        return class..'::'..self.name..'[tolua_index]'
     44    elseif class then
     45        return 'self->'..self.name..'[tolua_index]'
     46    else
     47        return self.name..'[tolua_index]'
     48    end
    4949end
    5050
    5151-- Write binding functions
    5252function classArray:supcode ()
    53  local class = self:inclass()
    54 
    55  -- get function ------------------------------------------------
    56  if class then
    57   output("/* get function:",self.name," of class ",class," */")
    58  else
    59   output("/* get function:",self.name," */")
    60  end
    61  self.cgetname = self:cfuncname("tolua_get")
    62  output("#ifndef TOLUA_DISABLE_"..self.cgetname)
    63  output("\nstatic int",self.cgetname,"(lua_State* tolua_S)")
    64  output("{")
    65  output(" int tolua_index;")
    66 
    67  -- declare self, if the case
    68  local _,_,static = strfind(self.mod,'^%s*(static)')
    69  if class and static==nil then
    70   output(' ',self.parent.type,'*','self;')
    71   output(' lua_pushstring(tolua_S,".self");')
    72   output(' lua_rawget(tolua_S,1);')
    73   output(' self = ')
    74   output('(',self.parent.type,'*) ')
    75   output('lua_touserdata(tolua_S,-1);')
    76  elseif static then
    77   _,_,self.mod = strfind(self.mod,'^%s*static%s%s*(.*)')
    78  end
    79 
    80  -- check index
    81         output('#ifndef TOLUA_RELEASE\n')
    82         output(' {')
    83         output('  tolua_Error tolua_err;')
    84  output('  if (!tolua_isnumber(tolua_S,2,0,&tolua_err))')
    85  output('   tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);')
    86         output(' }')
    87         output('#endif\n')
    88         if flags['1'] then -- for compatibility with tolua5 ?
    89                 output(' tolua_index = (int)tolua_tonumber(tolua_S,2,0)-1;')
    90         else
    91                 output(' tolua_index = (int)tolua_tonumber(tolua_S,2,0);')
    92         end
    93         output('#ifndef TOLUA_RELEASE\n')
    94         if self.dim and self.dim ~= '' then
    95           output(' if (tolua_index<0 || tolua_index>='..self.dim..')')
    96         else
    97           output(' if (tolua_index<0)')
    98         end
    99  output('  tolua_error(tolua_S,"array indexing out of range.",NULL);')
    100         output('#endif\n')
    101 
    102  -- return value
    103  local t,ct = isbasic(self.type)
    104  if t then
    105   output(' tolua_push'..t..'(tolua_S,(',ct,')'..self:getvalue(class,static)..');')
    106  else
    107                 t = self.type
    108   if self.ptr == '&' or self.ptr == '' then
    109    output(' tolua_pushusertype(tolua_S,(void*)&'..self:getvalue(class,static)..',"',t,'");')
    110   else
    111    output(' tolua_pushusertype(tolua_S,(void*)'..self:getvalue(class,static)..',"',t,'");')
    112   end
    113  end
    114  output(' return 1;')
    115  output('}')
    116  output('#endif //#ifndef TOLUA_DISABLE\n')
    117  output('\n')
    118 
    119  -- set function ------------------------------------------------
    120  if not strfind(self.type,'const') then
    121   if class then
    122    output("/* set function:",self.name," of class ",class," */")
    123   else
    124    output("/* set function:",self.name," */")
    125   end
    126   self.csetname = self:cfuncname("tolua_set")
    127   output("#ifndef TOLUA_DISABLE_"..self.csetname)
    128   output("\nstatic int",self.csetname,"(lua_State* tolua_S)")
    129   output("{")
    130 
    131   -- declare index
    132   output(' int tolua_index;')
    133 
    134   -- declare self, if the case
    135   local _,_,static = strfind(self.mod,'^%s*(static)')
    136   if class and static==nil then
    137    output(' ',self.parent.type,'*','self;')
    138    output(' lua_pushstring(tolua_S,".self");')
    139    output(' lua_rawget(tolua_S,1);')
    140    output(' self = ')
    141    output('(',self.parent.type,'*) ')
    142    output('lua_touserdata(tolua_S,-1);')
    143   elseif static then
    144    _,_,self.mod = strfind(self.mod,'^%s*static%s%s*(.*)')
    145   end
    146 
    147   -- check index
    148          output('#ifndef TOLUA_RELEASE\n')
    149          output(' {')
    150          output('  tolua_Error tolua_err;')
    151   output('  if (!tolua_isnumber(tolua_S,2,0,&tolua_err))')
    152   output('   tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);')
    153                 output(' }')
    154                 output('#endif\n')
    155 
    156         if flags['1'] then -- for compatibility with tolua5 ?
    157                 output(' tolua_index = (int)tolua_tonumber(tolua_S,2,0)-1;')
    158         else
    159                 output(' tolua_index = (int)tolua_tonumber(tolua_S,2,0);')
    160         end
    161 
    162          output('#ifndef TOLUA_RELEASE\n')
    163         if self.dim and self.dim ~= '' then
    164           output(' if (tolua_index<0 || tolua_index>='..self.dim..')')
    165         else
    166           output(' if (tolua_index<0)')
    167         end
    168   output('  tolua_error(tolua_S,"array indexing out of range.",NULL);')
    169                 output('#endif\n')
    170 
    171   -- assign value
    172   local ptr = ''
    173   if self.ptr~='' then ptr = '*' end
    174   output(' ')
    175   if class and static then
    176    output(class..'::'..self.name..'[tolua_index]')
    177   elseif class then
    178    output('self->'..self.name..'[tolua_index]')
    179   else
    180    output(self.name..'[tolua_index]')
    181   end
    182   local t = isbasic(self.type)
    183   output(' = ')
    184   if not t and ptr=='' then output('*') end
    185   output('((',self.mod,self.type)
    186   if not t then
    187    output('*')
    188   end
    189   output(') ')
    190   local def = 0
    191   if self.def ~= '' then def = self.def end
    192   if t then
    193    output('tolua_to'..t,'(tolua_S,3,',def,'));')
    194   else
    195    output('tolua_tousertype(tolua_S,3,',def,'));')
    196   end
    197   output(' return 0;')
    198   output('}')
    199   output('#endif //#ifndef TOLUA_DISABLE\n')
    200   output('\n')
    201  end
    202 
     53    local class = self:inclass()
     54
     55    -- get function ------------------------------------------------
     56    if class then
     57        output("/* get function:",self.name," of class ",class," */")
     58    else
     59        output("/* get function:",self.name," */")
     60    end
     61    self.cgetname = self:cfuncname("tolua_get")
     62    output("#ifndef TOLUA_DISABLE_"..self.cgetname)
     63    output("\nstatic int",self.cgetname,"(lua_State* tolua_S)")
     64    output("{")
     65    output(" int tolua_index;")
     66
     67    -- declare self, if the case
     68    local _,_,static = strfind(self.mod,'^%s*(static)')
     69    if class and static==nil then
     70        output(' ',self.parent.type,'*','self;')
     71        output(' lua_pushstring(tolua_S,".self");')
     72        output(' lua_rawget(tolua_S,1);')
     73        output(' self = ')
     74        output('(',self.parent.type,'*) ')
     75        output('lua_touserdata(tolua_S,-1);')
     76    elseif static then
     77        _,_,self.mod = strfind(self.mod,'^%s*static%s%s*(.*)')
     78    end
     79
     80    -- check index
     81    output('#ifndef TOLUA_RELEASE\n')
     82    output(' {')
     83    output('  tolua_Error tolua_err;')
     84    output('  if (!tolua_isnumber(tolua_S,2,0,&tolua_err))')
     85    output('   tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);')
     86    output(' }')
     87    output('#endif\n')
     88    if flags['1'] then -- for compatibility with tolua5 ?
     89        output(' tolua_index = (int)tolua_tonumber(tolua_S,2,0)-1;')
     90    else
     91        output(' tolua_index = (int)tolua_tonumber(tolua_S,2,0);')
     92    end
     93    output('#ifndef TOLUA_RELEASE\n')
     94    if self.dim and self.dim ~= '' then
     95        output(' if (tolua_index<0 || tolua_index>='..self.dim..')')
     96    else
     97        output(' if (tolua_index<0)')
     98    end
     99    output('  tolua_error(tolua_S,"array indexing out of range.",NULL);')
     100    output('#endif\n')
     101
     102    -- return value
     103    local t,ct = isbasic(self.type)
     104    if t then
     105        output(' tolua_push'..t..'(tolua_S,(',ct,')'..self:getvalue(class,static)..');')
     106    else
     107        t = self.type
     108        if self.ptr == '&' or self.ptr == '' then
     109            output(' tolua_pushusertype(tolua_S,(void*)&'..self:getvalue(class,static)..',"',t,'");')
     110        else
     111            output(' tolua_pushusertype(tolua_S,(void*)'..self:getvalue(class,static)..',"',t,'");')
     112        end
     113    end
     114    output(' return 1;')
     115    output('}')
     116    output('#endif //#ifndef TOLUA_DISABLE\n')
     117    output('\n')
     118
     119    -- set function ------------------------------------------------
     120    if not strfind(self.type,'const') then
     121        if class then
     122            output("/* set function:",self.name," of class ",class," */")
     123        else
     124            output("/* set function:",self.name," */")
     125        end
     126        self.csetname = self:cfuncname("tolua_set")
     127        output("#ifndef TOLUA_DISABLE_"..self.csetname)
     128        output("\nstatic int",self.csetname,"(lua_State* tolua_S)")
     129        output("{")
     130
     131        -- declare index
     132        output(' int tolua_index;')
     133
     134        -- declare self, if the case
     135        local _,_,static = strfind(self.mod,'^%s*(static)')
     136        if class and static==nil then
     137            output(' ',self.parent.type,'*','self;')
     138            output(' lua_pushstring(tolua_S,".self");')
     139            output(' lua_rawget(tolua_S,1);')
     140            output(' self = ')
     141            output('(',self.parent.type,'*) ')
     142            output('lua_touserdata(tolua_S,-1);')
     143        elseif static then
     144            _,_,self.mod = strfind(self.mod,'^%s*static%s%s*(.*)')
     145        end
     146
     147        -- check index
     148        output('#ifndef TOLUA_RELEASE\n')
     149        output(' {')
     150        output('  tolua_Error tolua_err;')
     151        output('  if (!tolua_isnumber(tolua_S,2,0,&tolua_err))')
     152        output('   tolua_error(tolua_S,"#vinvalid type in array indexing.",&tolua_err);')
     153        output(' }')
     154        output('#endif\n')
     155
     156        if flags['1'] then -- for compatibility with tolua5 ?
     157            output(' tolua_index = (int)tolua_tonumber(tolua_S,2,0)-1;')
     158        else
     159            output(' tolua_index = (int)tolua_tonumber(tolua_S,2,0);')
     160        end
     161
     162        output('#ifndef TOLUA_RELEASE\n')
     163        if self.dim and self.dim ~= '' then
     164            output(' if (tolua_index<0 || tolua_index>='..self.dim..')')
     165        else
     166            output(' if (tolua_index<0)')
     167        end
     168        output('  tolua_error(tolua_S,"array indexing out of range.",NULL);')
     169        output('#endif\n')
     170
     171        -- assign value
     172        local ptr = ''
     173        if self.ptr~='' then ptr = '*' end
     174            output(' ')
     175        if class and static then
     176            output(class..'::'..self.name..'[tolua_index]')
     177        elseif class then
     178            output('self->'..self.name..'[tolua_index]')
     179        else
     180            output(self.name..'[tolua_index]')
     181        end
     182        local t = isbasic(self.type)
     183        output(' = ')
     184        if not t and ptr=='' then output('*') end
     185        output('((',self.mod,self.type)
     186        if not t then
     187            output('*')
     188        end
     189        output(') ')
     190        local def = 0
     191        if self.def ~= '' then def = self.def end
     192        if t then
     193            output('tolua_to'..t,'(tolua_S,3,',def,'));')
     194        else
     195            output('tolua_tousertype(tolua_S,3,',def,'));')
     196        end
     197        output(' return 0;')
     198        output('}')
     199        output('#endif //#ifndef TOLUA_DISABLE\n')
     200        output('\n')
     201    end
    203202end
    204203
    205204function classArray:register (pre)
    206  pre = pre or ''
    207  if self.csetname then
    208   output(pre..'tolua_array(tolua_S,"'..self.lname..'",'..self.cgetname..','..self.csetname..');')
    209  else
    210   output(pre..'tolua_array(tolua_S,"'..self.lname..'",'..self.cgetname..',NULL);')
    211  end
     205    pre = pre or ''
     206    if self.csetname then
     207        output(pre..'tolua_array(tolua_S,"'..self.lname..'",'..self.cgetname..','..self.csetname..');')
     208    else
     209        output(pre..'tolua_array(tolua_S,"'..self.lname..'",'..self.cgetname..',NULL);')
     210    end
    212211end
    213212
    214213-- Internal constructor
    215214function _Array (t)
    216  setmetatable(t,classArray)
    217  append(t)
    218  return t
     215    setmetatable(t,classArray)
     216    append(t)
     217    return t
    219218end
    220219
     
    222221-- Expects a string representing the variable declaration.
    223222function Array (s)
    224  return _Array (Declaration(s,'var'))
    225 end
    226 
    227 
     223    return _Array (Declaration(s,'var'))
     224end
     225
     226
Note: See TracChangeset for help on using the changeset viewer.