Changeset 2509 for code/branches/buildsystem2/src/tolua/lua/basic.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/basic.lua
r2087 r2509 16 16 -- and all occurrences of "void*" will be replaced by "_userdata" 17 17 _basic = { 18 ['void'] = '',19 ['char'] = 'number',20 ['int'] = 'number',21 ['short'] = 'number',22 ['long'] = 'number',23 ['unsigned'] = 'number',24 ['float'] = 'number',25 ['double'] = 'number',26 ['_cstring'] = 'string',27 ['_userdata'] = 'userdata',28 ['char*'] = 'string',29 ['void*'] = 'userdata',30 ['bool'] = 'boolean',31 ['lua_Object'] = 'value',32 ['LUA_VALUE'] = 'value', -- for compatibility with tolua 4.033 ['lua_State*'] = 'state',34 ['_lstate'] = 'state',35 ['lua_Function'] = 'value',18 ['void'] = '', 19 ['char'] = 'number', 20 ['int'] = 'number', 21 ['short'] = 'number', 22 ['long'] = 'number', 23 ['unsigned'] = 'number', 24 ['float'] = 'number', 25 ['double'] = 'number', 26 ['_cstring'] = 'string', 27 ['_userdata'] = 'userdata', 28 ['char*'] = 'string', 29 ['void*'] = 'userdata', 30 ['bool'] = 'boolean', 31 ['lua_Object'] = 'value', 32 ['LUA_VALUE'] = 'value', -- for compatibility with tolua 4.0 33 ['lua_State*'] = 'state', 34 ['_lstate'] = 'state', 35 ['lua_Function'] = 'value', 36 36 } 37 37 38 38 _basic_ctype = { 39 number = "lua_Number",40 string = "const char*",41 userdata = "void*",42 boolean = "bool",43 value = "int",44 state = "lua_State*",39 number = "lua_Number", 40 string = "const char*", 41 userdata = "void*", 42 boolean = "bool", 43 value = "int", 44 state = "lua_State*", 45 45 } 46 46 … … 68 68 _renaming = {} 69 69 function appendrenaming (s) 70 local b,e,old,new = strfind(s,"%s*(.-)%s*@%s*(.-)%s*$")71 72 73 74 70 local b,e,old,new = strfind(s,"%s*(.-)%s*@%s*(.-)%s*$") 71 if not b then 72 error("#Invalid renaming syntax; it should be of the form: pattern@pattern") 73 end 74 tinsert(_renaming,{old=old, new=new}) 75 75 end 76 76 77 77 function applyrenaming (s) 78 79 80 81 82 83 84 78 for i=1,getn(_renaming) do 79 local m,n = gsub(s,_renaming[i].old,_renaming[i].new) 80 if n ~= 0 then 81 return m 82 end 83 end 84 return nil 85 85 end 86 86 87 87 -- Error handler 88 88 function tolua_error (s,f) 89 if _curr_code then90 91 92 end93 local out = _OUTPUT94 _OUTPUT = _STDERR95 if strsub(s,1,1) == '#' then96 write("\n** tolua: "..strsub(s,2)..".\n\n")97 if _curr_code then98 local _,_,s = strfind(_curr_code,"^%s*(.-\n)") -- extract first line99 if s==nil then s = _curr_code end100 s = gsub(s,"_userdata","void*") -- return with 'void*'101 s = gsub(s,"_cstring","char*") -- return with 'char*'102 s = gsub(s,"_lstate","lua_State*") -- return with 'lua_State*'103 write("Code being processed:\n"..s.."\n")104 end105 else106 if not f then f = "(f is nil)" end107 print("\n** tolua internal error: "..f..s..".\n\n")108 return109 end110 _OUTPUT = out89 if _curr_code then 90 print("***curr code for error is "..tostring(_curr_code)) 91 print(debug.traceback()) 92 end 93 local out = _OUTPUT 94 _OUTPUT = _STDERR 95 if strsub(s,1,1) == '#' then 96 write("\n** tolua: "..strsub(s,2)..".\n\n") 97 if _curr_code then 98 local _,_,s = strfind(_curr_code,"^%s*(.-\n)") -- extract first line 99 if s==nil then s = _curr_code end 100 s = gsub(s,"_userdata","void*") -- return with 'void*' 101 s = gsub(s,"_cstring","char*") -- return with 'char*' 102 s = gsub(s,"_lstate","lua_State*") -- return with 'lua_State*' 103 write("Code being processed:\n"..s.."\n") 104 end 105 else 106 if not f then f = "(f is nil)" end 107 print("\n** tolua internal error: "..f..s..".\n\n") 108 return 109 end 110 _OUTPUT = out 111 111 end 112 112 113 113 function warning (msg) 114 local out = _OUTPUT115 _OUTPUT = _STDERR116 write("\n** tolua warning: "..msg..".\n\n")117 _OUTPUT = out114 local out = _OUTPUT 115 _OUTPUT = _STDERR 116 write("\n** tolua warning: "..msg..".\n\n") 117 _OUTPUT = out 118 118 end 119 119 120 120 -- register an user defined type: returns full type 121 121 function regtype (t) 122 123 --return t124 125 126 127 128 129 130 122 --if isbasic(t) then 123 -- return t 124 --end 125 local ft = findtype(t) 126 127 if not _usertype[ft] then 128 return appendusertype(t) 129 end 130 return ft 131 131 end 132 132 133 133 -- return type name: returns full type 134 134 function typevar(type) 135 136 137 138 139 140 141 142 143 144 135 if type == '' or type == 'void' then 136 return type 137 else 138 local ft = findtype(type) 139 if ft then 140 return ft 141 end 142 _usertype[type] = type 143 return type 144 end 145 145 end 146 146 147 147 -- check if basic type 148 148 function isbasic (type) 149 local t = gsub(type,'const ','')150 local m,t = applytypedef('', t)151 local b = _basic[t]152 if b then153 return b,_basic_ctype[b]154 end155 return nil149 local t = gsub(type,'const ','') 150 local m,t = applytypedef('', t) 151 local b = _basic[t] 152 if b then 153 return b,_basic_ctype[b] 154 end 155 return nil 156 156 end 157 157 158 158 -- split string using a token 159 159 function split (s,t) 160 local l = {n=0}161 local f = function (s)162 l.n = l.n + 1163 l[l.n] = s164 return ""165 end166 local p = "%s*(.-)%s*"..t.."%s*"167 s = gsub(s,"^%s+","")168 s = gsub(s,"%s+$","")169 s = gsub(s,p,f)170 l.n = l.n + 1171 l[l.n] = gsub(s,"(%s%s*)$","")172 return l160 local l = {n=0} 161 local f = function (s) 162 l.n = l.n + 1 163 l[l.n] = s 164 return "" 165 end 166 local p = "%s*(.-)%s*"..t.."%s*" 167 s = gsub(s,"^%s+","") 168 s = gsub(s,"%s+$","") 169 s = gsub(s,p,f) 170 l.n = l.n + 1 171 l[l.n] = gsub(s,"(%s%s*)$","") 172 return l 173 173 end 174 174 … … 178 178 function split_c_tokens(s, pat) 179 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 --ret.n=1231 --ret[1] = ""232 233 234 180 s = string.gsub(s, "^%s*", "") 181 s = string.gsub(s, "%s*$", "") 182 183 local token_begin = 1 184 local token_end = 1 185 local ofs = 1 186 local ret = {n=0} 187 188 function add_token(ofs) 189 190 local t = string.sub(s, token_begin, ofs) 191 t = string.gsub(t, "^%s*", "") 192 t = string.gsub(t, "%s*$", "") 193 ret.n = ret.n + 1 194 ret[ret.n] = t 195 end 196 197 while ofs <= string.len(s) do 198 199 local sub = string.sub(s, ofs, -1) 200 local b,e = string.find(sub, "^"..pat) 201 if b then 202 add_token(ofs-1) 203 ofs = ofs+e 204 token_begin = ofs 205 else 206 local char = string.sub(s, ofs, ofs) 207 if char == "(" or char == "<" then 208 209 local block 210 if char == "(" then block = "^%b()" end 211 if char == "<" then block = "^%b<>" end 212 213 b,e = string.find(sub, block) 214 if not b then 215 -- unterminated block? 216 ofs = ofs+1 217 else 218 ofs = ofs + e 219 end 220 221 else 222 ofs = ofs+1 223 end 224 end 225 226 end 227 add_token(ofs) 228 --if ret.n == 0 then 229 230 -- ret.n=1 231 -- ret[1] = "" 232 --end 233 234 return ret 235 235 236 236 end … … 238 238 -- concatenate strings of a table 239 239 function concat (t,f,l,jstr) 240 241 local s = ''242 local i=f243 while i<=l do244 s = s..t[i]245 i = i+1246 if i <= l then s = s..jstr end247 end248 return s240 jstr = jstr or " " 241 local s = '' 242 local i=f 243 while i<=l do 244 s = s..t[i] 245 i = i+1 246 if i <= l then s = s..jstr end 247 end 248 return s 249 249 end 250 250 251 251 -- concatenate all parameters, following output rules 252 252 function concatparam (line, ...) 253 local i=1254 while i<=arg.n do255 if _cont and not strfind(_cont,'[%(,"]') and256 strfind(arg[i],"^[%a_~]") then257 258 end259 line = line .. arg[i]260 if arg[i] ~= '' then261 _cont = strsub(arg[i],-1,-1)262 end263 i = i+1264 end265 if strfind(arg[arg.n],"[%/%)%;%{%}]$") then266 _cont=nil line = line .. '\n'267 end268 253 local i=1 254 while i<=arg.n do 255 if _cont and not strfind(_cont,'[%(,"]') and 256 strfind(arg[i],"^[%a_~]") then 257 line = line .. ' ' 258 end 259 line = line .. arg[i] 260 if arg[i] ~= '' then 261 _cont = strsub(arg[i],-1,-1) 262 end 263 i = i+1 264 end 265 if strfind(arg[arg.n],"[%/%)%;%{%}]$") then 266 _cont=nil line = line .. '\n' 267 end 268 return line 269 269 end 270 270 271 271 -- output line 272 272 function output (...) 273 local i=1274 while i<=arg.n do275 if _cont and not strfind(_cont,'[%(,"]') and276 strfind(arg[i],"^[%a_~]") then277 278 end279 write(arg[i])280 if arg[i] ~= '' then281 _cont = strsub(arg[i],-1,-1)282 end283 i = i+1284 end285 if strfind(arg[arg.n],"[%/%)%;%{%}]$") then286 _cont=nil write('\n')287 end273 local i=1 274 while i<=arg.n do 275 if _cont and not strfind(_cont,'[%(,"]') and 276 strfind(arg[i],"^[%a_~]") then 277 write(' ') 278 end 279 write(arg[i]) 280 if arg[i] ~= '' then 281 _cont = strsub(arg[i],-1,-1) 282 end 283 i = i+1 284 end 285 if strfind(arg[arg.n],"[%/%)%;%{%}]$") then 286 _cont=nil write('\n') 287 end 288 288 end 289 289 290 290 function get_property_methods(ptype, name) 291 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 292 if get_property_methods_hook and get_property_methods_hook(ptype,name) then 293 return get_property_methods_hook(ptype, name) 294 end 295 296 if ptype == "default" then -- get_name, set_name 297 return "get_"..name, "set_"..name 298 end 299 300 if ptype == "qt" then -- name, setName 301 return name, "set"..string.upper(string.sub(name, 1, 1))..string.sub(name, 2, -1) 302 end 303 304 if ptype == "overload" then -- name, name 305 return name,name 306 end 307 308 return nil 309 309 end 310 310 … … 315 315 -- takes the package object as the parameter 316 316 function preprocess_hook(p) 317 317 -- p.code has all the input code from the pkg 318 318 end 319 319 … … 351 351 function parser_hook(s) 352 352 353 354 end 355 356 353 return nil 354 end 355 356
Note: See TracChangeset
for help on using the changeset viewer.