Changeset 2509 for code/branches/buildsystem2/src/tolua/lua/array.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/array.lua
r2087 r2509 21 21 -- Print method 22 22 function 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) 32 32 end 33 33 34 34 -- check if it is a variable 35 35 function classArray:isvariable () 36 return true36 return true 37 37 end 38 38 … … 40 40 -- get variable value 41 41 function classArray:getvalue (class,static) 42 if class and static then43 return class..'::'..self.name..'[tolua_index]'44 elseif class then45 return 'self->'..self.name..'[tolua_index]'46 else47 return self.name..'[tolua_index]'48 end42 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 49 49 end 50 50 51 51 -- Write binding functions 52 52 function 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 203 202 end 204 203 205 204 function classArray:register (pre) 206 pre = pre or ''207 if self.csetname then208 output(pre..'tolua_array(tolua_S,"'..self.lname..'",'..self.cgetname..','..self.csetname..');')209 else210 output(pre..'tolua_array(tolua_S,"'..self.lname..'",'..self.cgetname..',NULL);')211 end205 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 212 211 end 213 212 214 213 -- Internal constructor 215 214 function _Array (t) 216 setmetatable(t,classArray)217 append(t)218 return t215 setmetatable(t,classArray) 216 append(t) 217 return t 219 218 end 220 219 … … 222 221 -- Expects a string representing the variable declaration. 223 222 function Array (s) 224 return _Array (Declaration(s,'var'))225 end 226 227 223 return _Array (Declaration(s,'var')) 224 end 225 226
Note: See TracChangeset
for help on using the changeset viewer.