Changeset 3138 for code/branches/pch/src/tolua/lua
- Timestamp:
- Jun 10, 2009, 4:01:42 PM (16 years ago)
- Location:
- code/branches/pch/src/tolua/lua
- Files:
-
- 1 deleted
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pch/src/tolua/lua/array.lua
r3127 r3138 102 102 -- return value 103 103 local t,ct = isbasic(self.type) 104 local push_func = get_push_function(t)105 104 if t then 106 105 output(' tolua_push'..t..'(tolua_S,(',ct,')'..self:getvalue(class,static)..');') … … 108 107 t = self.type 109 108 if self.ptr == '&' or self.ptr == '' then 110 output(' ',push_func,'(tolua_S,(void*)&'..self:getvalue(class,static)..',"',t,'");')111 else 112 output(' ',push_func,'(tolua_S,(void*)'..self:getvalue(class,static)..',"',t,'");')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,'");') 113 112 end 114 113 end … … 194 193 output('tolua_to'..t,'(tolua_S,3,',def,'));') 195 194 else 196 local to_func = get_to_function(self.type) 197 output(to_func,'(tolua_S,3,',def,'));') 195 output('tolua_tousertype(tolua_S,3,',def,'));') 198 196 end 199 197 output(' return 0;') … … 205 203 206 204 function classArray:register (pre) 207 if not self:check_public_access() then208 return209 end210 211 205 pre = pre or '' 212 206 if self.csetname then -
code/branches/pch/src/tolua/lua/basic.lua
r3129 r3138 112 112 113 113 function warning (msg) 114 if flags.q then115 return116 end117 114 local out = _OUTPUT 118 115 _OUTPUT = _STDERR … … 336 333 end 337 334 338 -- called before starting output339 function pre_output_hook(package)340 341 end342 335 343 336 -- called after writing all the output. … … 361 354 end 362 355 363 -- called from classFunction:supcode, before the call to the function is output 364 function pre_call_hook(f) 365 366 end 367 368 -- called from classFunction:supcode, after the call to the function is output 369 function post_call_hook(f) 370 371 end 372 373 -- called before the register code is output 374 function pre_register_hook(package) 375 376 end 377 378 -- called to output an error message 379 function output_error_hook(str, arg) 380 return string.format(str, arg) 381 end 382 383 -- custom pushers 384 385 _push_functions = {} 386 _is_functions = {} 387 _to_functions = {} 388 389 _base_push_functions = {} 390 _base_is_functions = {} 391 _base_to_functions = {} 392 393 local function search_base(t, funcs) 394 local class = _global_classes[t] 395 396 while class do 397 if funcs[class.type] then 398 return funcs[class.type] 399 end 400 class = _global_classes[class.btype] 401 end 402 return nil 403 end 404 405 function get_push_function(t) 406 return _push_functions[t] or search_base(t, _base_push_functions) or "tolua_pushusertype" 407 end 408 409 function get_to_function(t) 410 return _to_functions[t] or search_base(t, _base_to_functions) or "tolua_tousertype" 411 end 412 413 function get_is_function(t) 414 return _is_functions[t] or search_base(t, _base_is_functions) or "tolua_isusertype" 415 end 416 356 -
code/branches/pch/src/tolua/lua/class.lua
r3127 r3138 64 64 -- return collection requirement 65 65 function classClass:requirecollection (t) 66 if self.flags.protected_destructor or (not self:check_public_access())then66 if self.flags.protected_destructor then 67 67 return false 68 68 end … … 148 148 -- check for template 149 149 b = string.gsub(b, "^{%s*TEMPLATE_BIND", "{\nTOLUA_TEMPLATE_BIND") 150 local t,_,T,I = string.find(b, '^{%s*TOLUA_TEMPLATE_BIND%s*%(+%s*\"?([^\",]*)\"?%s*,%s*([^%)]*)%s*%)+')150 local t,_,T,I = string.find(b, "^{%s*TOLUA_TEMPLATE_BIND%s*%(+%s*\"?([^\",]*)\"?%s*,%s*([^%)]*)%s*%)+") 151 151 if t then 152 152 … … 159 159 local bs = string.gsub(b, "^{%s*TOLUA_TEMPLATE_BIND[^\n]*\n", "{\n") 160 160 161 local Tl = split(T, " ") 162 local tc = TemplateClass(n, p, bs, Tl) 163 164 tc:throw(types, true) 165 --for i=1,types.n do 166 -- tc:throw(split_c_tokens(types[i], " "), true) 167 --end 161 -- replace 162 for i =1 , types.n do 163 164 local Tl = split(T, " ") 165 local Il = split_c_tokens(types[i], " ") 166 local bI = bs 167 local pI = {} 168 for j = 1,Tl.n do 169 Tl[j] = findtype(Tl[j]) or Tl[j] 170 bI = string.gsub(bI, "([^_%w])"..Tl[j].."([^_%w])", "%1"..Il[j].."%2") 171 if p then 172 for i=1,table.getn(p) do 173 pI[i] = string.gsub(p[i], "([^_%w]?)"..Tl[j].."([^_%w]?)", "%1"..Il[j].."%2") 174 end 175 end 176 end 177 --local append = "<"..string.gsub(types[i], "%s+", ",")..">" 178 local append = "<"..concat(Il, 1, table.getn(Il), ",")..">" 179 append = string.gsub(append, "%s*,%s*", ",") 180 append = string.gsub(append, ">>", "> >") 181 for i=1,table.getn(pI) do 182 --pI[i] = string.gsub(pI[i], ">>", "> >") 183 pI[i] = resolve_template_types(pI[i]) 184 end 185 bI = string.gsub(bI, ">>", "> >") 186 Class(n..append, pI, bI) 187 end 168 188 return 169 189 end -
code/branches/pch/src/tolua/lua/code.lua
r3127 r3138 47 47 end 48 48 49 -- pad to 16 bytes50 local npad = 16 - (#s % 16)51 local spad = ""52 for i=1,npad do53 spad = spad .. "-"54 end55 s = s..spad56 57 49 -- convert to C 58 50 output('\n'..pre..'{ /* begin embedded lua code */\n') 59 51 output(pre..' int top = lua_gettop(tolua_S);') 60 output(pre..' static constunsigned char B[] = {\n ')52 output(pre..' static unsigned char B[] = {\n ') 61 53 local t={n=0} 62 54 local b = gsub(s, '(.)', -
code/branches/pch/src/tolua/lua/compat-5.1.lua
r3127 r3138 26 26 27 27 local f = load(getfile, path) 28 if not f then29 error("error loading file "..path)30 end31 28 return f() 32 29 end -
code/branches/pch/src/tolua/lua/container.lua
r3127 r3138 615 615 b,e,decl,arg,const = strfind(s,"^%s*([_%w])%s*(%b())%s*(c?o?n?s?t?)%s*;%s*") 616 616 end 617 if not b then618 -- try function pointer619 b,e,decl,arg,const = strfind(s,"^%s*([^%(;\n]+%b())%s*(%b())%s*;%s*")620 if b then621 decl = string.gsub(decl, "%(%s*%*([^%)]*)%s*%)", " %1 ")622 end623 end624 617 if b then 625 618 if virt and string.find(virt, "[=0]") then … … 654 647 base = '' body = '' 655 648 b,e,name = strfind(s,"^%s*class%s*([_%w][_%w@]*)%s*;") -- dummy class 656 local dummy = false657 649 if not b then 658 650 b,e,name = strfind(s,"^%s*struct%s*([_%w][_%w@]*)%s*;") -- dummy struct 659 651 if not b then 660 b,e,name,base,body = strfind(s,"^%s*class%s*([_%w][_%w@]*)%s*( [^{]-)%s*(%b{})%s*")652 b,e,name,base,body = strfind(s,"^%s*class%s*([_%w][_%w@]*)%s*(.-)%s*(%b{})%s*;%s*") 661 653 if not b then 662 b,e,name,base,body = strfind(s,"^%s*struct%s +([_%w][_%w@]*)%s*([^{]-)%s*(%b{})%s*")654 b,e,name,base,body = strfind(s,"^%s*struct%s*([_%w][_%w@]*)%s*(.-)%s*(%b{})%s*;%s*") 663 655 if not b then 664 b,e,name,base,body = strfind(s,"^%s*union%s*([_%w][_%w@]*)%s*( [^{]-)%s*(%b{})%s*")656 b,e,name,base,body = strfind(s,"^%s*union%s*([_%w][_%w@]*)%s*(.-)%s*(%b{})%s*;%s*") 665 657 if not b then 666 658 base = '' 667 b,e,body,name = strfind(s,"^%s*typedef%s%s*struct%s%s*[_%w]*%s*(%b{})%s*([_%w][_%w@]*)%s*; ")659 b,e,body,name = strfind(s,"^%s*typedef%s%s*struct%s%s*[_%w]*%s*(%b{})%s*([_%w][_%w@]*)%s*;%s*") 668 660 end 669 661 end 670 662 end 671 e lse dummy = 1 end672 e lse dummy = 1 end663 end 664 end 673 665 if b then 674 666 if base ~= '' then … … 683 675 _curr_code = strsub(s,b,e) 684 676 Class(name,base,body) 685 if not dummy then686 varb,vare,varname = string.find(s, "^%s*([_%w]+)%s*;", e+1)687 if varb then688 Variable(name.." "..varname)689 e = vare690 end691 end692 677 return strsub(s,e+1) 693 678 end … … 738 723 -- try array 739 724 do 740 local b,e,decl = strfind(s,"^%s*([_%w][][_@%s%w%d%*&:<>]*[]_%w%d])%s*;%s*")725 local b,e,decl = strfind(s,"^%s*([_%w][][_@%s%w%d%*&:]*[]_%w%d])%s*;%s*") 741 726 if b then 742 727 _curr_code = strsub(s,b,e) … … 758 743 function classContainer:parse (s) 759 744 760 --self.curr_member_access = nil745 self.curr_member_access = nil 761 746 762 747 while s ~= '' do -
code/branches/pch/src/tolua/lua/declaration.lua
r3127 r3138 140 140 for i=1, table.getn(m) do 141 141 m[i] = string.gsub(m[i],"%s*([%*&])", "%1") 142 if not isbasic(m[i]) then 143 if not isenum(m[i]) then _, m[i] = applytypedef("", m[i]) end 144 m[i] = findtype(m[i]) or m[i] 145 m[i] = resolve_template_types(m[i]) 146 end 142 m[i] = findtype(m[i]) or m[i] 143 m[i] = resolve_template_types(m[i]) 147 144 end 148 145 149 146 local b,i 150 147 type,b,i = break_template(type) 151 --print("concat is ",concat(m, 1, m.n)) 152 local template_part = "<"..concat(m, 1, m.n, ",")..">" 148 local template_part = "<"..string.gsub(concat(m, 1, m.n), " ", ",")..">" 153 149 type = rebuild_template(type, b, template_part) 154 150 type = string.gsub(type, ">>", "> >") … … 191 187 -- check if array of values are returned to Lua 192 188 function classDeclaration:requirecollection (t) 193 189 if self.mod ~= 'const' and 194 190 self.dim and self.dim ~= '' and 195 191 not isbasic(self.type) and 196 self.ptr == '' and self:check_public_access()then192 self.ptr == '' then 197 193 local type = gsub(self.type,"%s*const%s+","") 198 194 t[type] = "tolua_collect_" .. clean_template(type) … … 226 222 -- return 'tolua_isstringarray(tolua_S,'..narg..','..def..',&tolua_err)' 227 223 --else 228 return ' !tolua_istable(tolua_S,'..narg..',0,&tolua_err)'224 return 'tolua_istable(tolua_S,'..narg..',0,&tolua_err)' 229 225 --end 230 226 elseif t then 231 return '!tolua_is'..t..'(tolua_S,'..narg..','..def..',&tolua_err)' 232 else 233 local is_func = get_is_function(self.type) 234 if self.ptr == '&' or self.ptr == '' then 235 return '(tolua_isvaluenil(tolua_S,'..narg..',&tolua_err) || !'..is_func..'(tolua_S,'..narg..',"'..self.type..'",'..def..',&tolua_err))' 236 else 237 return '!'..is_func..'(tolua_S,'..narg..',"'..self.type..'",'..def..',&tolua_err)' 238 end 239 end 227 return 'tolua_is'..t..'(tolua_S,'..narg..','..def..',&tolua_err)' 228 else 229 return 'tolua_isusertype(tolua_S,'..narg..',"'..self.type..'",'..def..',&tolua_err)' 230 end 240 231 end 241 232 … … 246 237 local mod 247 238 local type = self.type 248 local nctype = gsub(self.type,'const%s+','')249 239 if self.dim ~= '' then 250 240 type = gsub(self.type,'const%s+','') -- eliminates const modifier for arrays … … 261 251 else 262 252 if cplusplus then 263 line = concatparam(line,' = Mtolua_new_dim(',type,ptr,', '..self.dim..');')253 line = concatparam(line,' = new',type,ptr,'['..self.dim..'];') 264 254 else 265 255 line = concatparam(line,' = (',type,ptr,'*)', … … 283 273 end 284 274 line = concatparam(line,') ') 285 if isenum( nctype) then275 if isenum(type) then 286 276 line = concatparam(line,'(int) ') 287 277 end … … 296 286 line = concatparam(line,'tolua_to'..t,'(tolua_S,',narg,',',def,'));') 297 287 else 298 local to_func = get_to_function(type) 299 line = concatparam(line,to_func..'(tolua_S,',narg,',',def,'));') 288 line = concatparam(line,'tolua_tousertype(tolua_S,',narg,',',def,'));') 300 289 end 301 290 end … … 372 361 output(' {') 373 362 output('#ifdef __cplusplus\n') 374 output(' void* tolua_obj = Mtolua_new((',type,')(',self.name,'[i]));')363 output(' void* tolua_obj = new',type,'(',self.name,'[i]);') 375 364 output(' tolua_pushfieldusertype_and_takeownership(tolua_S,',narg,',i+1,tolua_obj,"',type,'");') 376 365 output('#else\n') … … 391 380 if self.dim ~= '' and tonumber(self.dim)==nil then 392 381 output('#ifdef __cplusplus\n') 393 output(' Mtolua_delete_dim(',self.name,');')382 output(' delete []',self.name,';') 394 383 output('#else\n') 395 384 output(' free(',self.name,');') … … 416 405 output(' tolua_push'..t..'(tolua_S,(',ct,')'..self.name..');') 417 406 else 418 local push_func = get_push_function(self.type) 419 output(' ',push_func,'(tolua_S,(void*)'..self.name..',"',self.type,'");') 407 output(' tolua_pushusertype(tolua_S,(void*)'..self.name..',"',self.type,'");') 420 408 end 421 409 return 1 -
code/branches/pch/src/tolua/lua/doit.lua
r3127 r3138 16 16 for k,v in ipairs(_extra_parameters or {}) do 17 17 18 local b,e,name,value = string.find(v, "^([^=] *)=(.*)$")18 local b,e,name,value = string.find(v, "^([^=])=(.*)$") 19 19 if b then 20 20 _extra_parameters[name] = value … … 94 94 p:print() 95 95 else 96 push(p)97 pre_output_hook(p)98 pop()99 96 p:preamble() 100 97 p:supcode() 101 push(p)102 pre_register_hook(p)103 pop()104 98 p:register() 105 99 push(p) -
code/branches/pch/src/tolua/lua/enumerate.lua
r3127 r3138 22 22 -- register enumeration 23 23 function classEnumerate:register (pre) 24 if not self:check_public_access() then25 return26 end27 24 pre = pre or '' 28 25 local nspace = getnamespace(classContainer.curr) 29 26 local i=1 30 27 while self[i] do 31 if self.lnames[i] and self.lnames[i] ~= "" then 32 output(pre..'tolua_constant(tolua_S,"'..self.lnames[i]..'",'..nspace..self[i]..');') 33 end 28 output(pre..'tolua_constant(tolua_S,"'..self.lnames[i]..'",'..nspace..self[i]..');') 34 29 i = i+1 35 30 end … … 61 56 Variable("tolua_readonly int "..varname) 62 57 end 63 end64 local parent = classContainer.curr65 if parent then66 t.access = parent.curr_member_access67 t.global_access = t:check_public_access()68 58 end 69 59 return t -
code/branches/pch/src/tolua/lua/feature.lua
r3127 r3138 48 48 local n = split(self.name,'@') 49 49 self.name = n[1] 50 self.name = string.gsub(self.name, ":%d*$", "")51 50 if not n[2] then 52 51 n[2] = applyrenaming(n[1]) 53 52 end 54 53 self.lname = n[2] or gsub(n[1],"%[.-%]","") 55 self.lname = string.gsub(self.lname, ":%d*$", "")56 54 self.original_name = self.name 57 55 self.lname = clean_template(self.lname) … … 64 62 if parent then 65 63 self.access = parent.curr_member_access 66 self.global_access = self:check_public_access()67 64 else 68 65 end … … 70 67 71 68 function classFeature:check_public_access() 72 73 if type(self.global_access) == "boolean" then74 return self.global_access75 end76 69 77 70 if self.access and self.access ~= 0 then … … 129 122 end 130 123 131 local fname = self.lname 132 if not fname or fname == '' then 133 fname = self.name 134 end 135 n = string.gsub(n..'_'.. (fname), "[<>:, \.%*&]", "_") 124 n = string.gsub(n..'_'.. (self.lname or self.name), "[<>:, \.%*&]", "_") 136 125 137 126 return n -
code/branches/pch/src/tolua/lua/function.lua
r3127 r3138 209 209 if class then narg=2 else narg=1 end 210 210 if class then 211 local func = get_is_function(self.parent.type)211 local func = 'tolua_isusertype' 212 212 local type = self.parent.type 213 213 if self.name=='new' or static~=nil then … … 226 226 local btype = isbasic(self.args[i].type) 227 227 if btype ~= 'value' and btype ~= 'state' then 228 output(' '..self.args[i]:outchecktype(narg)..' ||\n')228 output(' !'..self.args[i]:outchecktype(narg)..' ||\n') 229 229 end 230 230 if btype ~= 'state' then … … 250 250 output(' ',self.const,self.parent.type,'*','self = ') 251 251 output('(',self.const,self.parent.type,'*) ') 252 local to_func = get_to_function(self.parent.type) 253 output(to_func,'(tolua_S,1,0);') 252 output('tolua_tousertype(tolua_S,1,0);') 254 253 elseif static then 255 254 _,_,self.mod = strfind(self.mod,'^%s*static%s%s*(.*)') … … 270 269 if class and self.name~='new' and static==nil then 271 270 output('#ifndef TOLUA_RELEASE\n') 272 output(' if (!self) tolua_error(tolua_S," '..output_error_hook("invalid \'self\' in function \'%s\'", self.name)..'",NULL);');271 output(' if (!self) tolua_error(tolua_S,"invalid \'self\' in function \''..self.name..'\'",NULL);'); 273 272 output('#endif\n') 274 273 end … … 313 312 -------------------------------------------------- 314 313 315 pre_call_hook(self)316 317 314 local out = string.find(self.mod, "tolua_outside") 318 315 … … 326 323 -- call function 327 324 if class and self.name=='delete' then 328 output(' Mtolua_delete(self);')325 output(' delete self;') 329 326 elseif class and self.name == 'operator&[]' then 330 327 if flags['1'] then -- for compatibility with tolua5 ? … … 355 352 end 356 353 if class and self.name=='new' then 357 output(' Mtolua_new((',self.type,')(')354 output('new',self.type,'(') 358 355 elseif class and static then 359 356 if out then … … 367 364 else 368 365 if self.cast_operator then 369 --output('static_cast<',self.mod,self.type,self.ptr,' >(*self') 370 output('self->operator ',self.mod,self.type,'(') 366 output('static_cast<',self.mod,self.type,self.ptr,'>(*self') 371 367 else 372 368 output('self->'..self.name,'(') … … 396 392 output('-1);') 397 393 else 398 if class and self.name=='new' then 399 output('));') -- close Mtolua_new( 400 else 401 output(');') 402 end 394 output(');') 403 395 end 404 396 … … 407 399 nret = nret + 1 408 400 local t,ct = isbasic(self.type) 409 if t and self.name ~= "new"then401 if t then 410 402 if self.cast_operator and _basic_raw_push[t] then 411 403 output(' ',_basic_raw_push[t],'(tolua_S,(',ct,')tolua_ret);') … … 416 408 t = self.type 417 409 new_t = string.gsub(t, "const%s+", "") 418 local owned = false419 if string.find(self.mod, "tolua_owned") then420 owned = true421 end422 local push_func = get_push_function(t)423 410 if self.ptr == '' then 424 411 output(' {') 425 412 output('#ifdef __cplusplus\n') 426 output(' void* tolua_obj = Mtolua_new((',new_t,')(tolua_ret));') 427 output(' ',push_func,'(tolua_S,tolua_obj,"',t,'");') 428 output(' tolua_register_gc(tolua_S,lua_gettop(tolua_S));') 413 output(' void* tolua_obj = new',new_t,'(tolua_ret);') 414 output(' tolua_pushusertype_and_takeownership(tolua_S,tolua_obj,"',t,'");') 429 415 output('#else\n') 430 416 output(' void* tolua_obj = tolua_copy(tolua_S,(void*)&tolua_ret,sizeof(',t,'));') 431 output(' ',push_func,'(tolua_S,tolua_obj,"',t,'");') 432 output(' tolua_register_gc(tolua_S,lua_gettop(tolua_S));') 417 output(' tolua_pushusertype_and_takeownership(tolua_S,tolua_obj,"',t,'");') 433 418 output('#endif\n') 434 419 output(' }') 435 420 elseif self.ptr == '&' then 436 output(' ',push_func,'(tolua_S,(void*)&tolua_ret,"',t,'");')421 output(' tolua_pushusertype(tolua_S,(void*)&tolua_ret,"',t,'");') 437 422 else 438 output(' ',push_func,'(tolua_S,(void*)tolua_ret,"',t,'");') 439 if owned or local_constructor then 440 output(' tolua_register_gc(tolua_S,lua_gettop(tolua_S));') 423 if local_constructor then 424 output(' tolua_pushusertype_and_takeownership(tolua_S,(void *)tolua_ret,"',t,'");') 425 else 426 output(' tolua_pushusertype(tolua_S,(void*)tolua_ret,"',t,'");') 441 427 end 442 428 end … … 480 466 end 481 467 482 post_call_hook(self)483 484 468 output(' }') 485 469 output(' return '..nret..';') … … 490 474 output('#ifndef TOLUA_RELEASE\n') 491 475 output('tolua_lerror:\n') 492 output(' tolua_error(tolua_S," '..output_error_hook("#ferror in function \'%s\'.", self.lname)..'",&tolua_err);')476 output(' tolua_error(tolua_S,"#ferror in function \''..self.lname..'\'.",&tolua_err);') 493 477 output(' return 0;') 494 478 output('#endif\n') … … 590 574 if string.find(par, "%*") then -- it's a pointer with a default value 591 575 592 if string.find(par, '=%s*new') or string.find(par, "%(")then -- it's a pointer with an instance as default parameter.. is that valid?576 if string.find(par, '=%s*new') then -- it's a pointer with an instance as default parameter.. is that valid? 593 577 return true 594 578 end … … 677 661 --ns = strip_defaults(ns) 678 662 679 local f =Function(d, ns, c)663 Function(d, ns, c) 680 664 for i=1,last do 681 665 t[i] = string.gsub(t[i], "=.*$", "") -
code/branches/pch/src/tolua/lua/operator.lua
r3127 r3138 75 75 output(' if (\n') 76 76 -- check self 77 local is_func = get_is_function(self.parent.type) 78 output(' !'..is_func..'(tolua_S,1,"'..self.parent.type..'",0,&tolua_err) ||\n') 77 output(' !'..'tolua_isusertype(tolua_S,1,"'..self.parent.type..'",0,&tolua_err) ||\n') 79 78 output(' !tolua_isnoobj(tolua_S,2,&tolua_err)\n )') 80 79 output(' goto tolua_lerror;') … … 87 86 output(' ',self.const,self.parent.type,'*','self = ') 88 87 output('(',self.const,self.parent.type,'*) ') 89 local to_func = get_to_func(self.parent.type) 90 output(to_func,'(tolua_S,1,0);') 88 output('tolua_tousertype(tolua_S,1,0);') 91 89 92 90 -- check self 93 91 output('#ifndef TOLUA_RELEASE\n') 94 output(' if (!self) tolua_error(tolua_S," '..output_error_hook("invalid \'self\' in function \'%s\'", self.name)..'",NULL);');92 output(' if (!self) tolua_error(tolua_S,"invalid \'self\' in function \''..self.name..'\'",NULL);'); 95 93 output('#endif\n') 96 94 … … 105 103 else 106 104 t = self.type 107 local push_func = get_push_function(t)108 105 new_t = string.gsub(t, "const%s+", "") 109 106 if self.ptr == '' then 110 107 output(' {') 111 108 output('#ifdef __cplusplus\n') 112 output(' void* tolua_obj = Mtolua_new((',new_t,')(tolua_ret));') 113 output(' ',push_func,'(tolua_S,tolua_obj,"',t,'");') 114 output(' tolua_register_gc(tolua_S,lua_gettop(tolua_S));') 109 output(' void* tolua_obj = new',new_t,'(tolua_ret);') 110 output(' tolua_pushusertype_and_takeownership(tolua_S,tolua_obj,"',t,'");') 115 111 output('#else\n') 116 112 output(' void* tolua_obj = tolua_copy(tolua_S,(void*)&tolua_ret,sizeof(',t,'));') 117 output(' ',push_func,'(tolua_S,tolua_obj,"',t,'");') 118 output(' tolua_register_gc(tolua_S,lua_gettop(tolua_S));') 113 output(' tolua_pushusertype_and_takeownership(tolua_S,tolua_obj,"',t,'");') 119 114 output('#endif\n') 120 115 output(' }') 121 116 elseif self.ptr == '&' then 122 output(' ',push_func,'(tolua_S,(void*)&tolua_ret,"',t,'");')117 output(' tolua_pushusertype(tolua_S,(void*)&tolua_ret,"',t,'");') 123 118 else 124 119 if local_constructor then 125 output(' ',push_func,'(tolua_S,(void *)tolua_ret,"',t,'");') 126 output(' tolua_register_gc(tolua_S,lua_gettop(tolua_S));') 120 output(' tolua_pushusertype_and_takeownership(tolua_S,(void *)tolua_ret,"',t,'");') 127 121 else 128 output(' ',push_func,'(tolua_S,(void*)tolua_ret,"',t,'");')122 output(' tolua_pushusertype(tolua_S,(void*)tolua_ret,"',t,'");') 129 123 end 130 124 end … … 136 130 output('#ifndef TOLUA_RELEASE\n') 137 131 output('tolua_lerror:\n') 138 output(' tolua_error(tolua_S," '..output_error_hook("#ferror in function \'%s\'.", self.lname)..'",&tolua_err);')132 output(' tolua_error(tolua_S,"#ferror in function \''..self.lname..'\'.",&tolua_err);') 139 133 output(' return 0;') 140 134 output('#endif\n') -
code/branches/pch/src/tolua/lua/package.lua
r3129 r3138 146 146 output('{') 147 147 output(' '..i..'* self = ('..i..'*) tolua_tousertype(tolua_S,1,0);') 148 output(' Mtolua_delete(self);')148 output(' delete self;') 149 149 output(' return 0;') 150 150 output('}') … … 157 157 output('static void tolua_reg_types (lua_State* tolua_S)') 158 158 output('{') 159 159 foreach(_usertype,function(n,v) output(' tolua_usertype(tolua_S,"',v,'");') end) 160 160 if flags.t then 161 161 output("#ifndef Mtolua_typeid\n#define Mtolua_typeid(L,TI,T)\n#endif\n") 162 end 163 foreach(_usertype,function(n,v) 164 if (not _global_classes[v]) or _global_classes[v]:check_public_access() then 165 output(' tolua_usertype(tolua_S,"',v,'");') 166 if flags.t then 167 output(' Mtolua_typeid(tolua_S,typeid(',v,'), "',v,'");') 168 end 169 end 170 end) 171 output('}') 162 foreach(_usertype,function(n,v) output(' Mtolua_typeid(tolua_S,typeid(',v,'), "',v,'");') end) 163 end 164 output('}') 172 165 output('\n') 173 166 end … … 256 249 257 250 -- open input file, if any 258 local st,msg259 251 if fn then 260 252 local file … … 268 260 file = flags.f 269 261 end 270 st, msg = readfrom(file)262 local st, msg = readfrom(file) 271 263 if not st then 272 264 error('#'..msg..' path: '..flags.f) … … 274 266 local _; _, _, ext = strfind(fn,".*%.(.*)$") 275 267 end 276 local code 277 if ext == 'pkg' then 278 code = prep(st) 279 else 280 code = "\n" .. read('*a') 281 if ext == 'h' or ext == 'hpp' then 282 code = extract_code(fn,code) 283 end 268 local code = "\n" .. read('*a') 269 if ext == 'h' or ext == 'hpp' then 270 code = extract_code(fn,code) 284 271 end 285 272 … … 313 300 error('#'..msg..': '..fn) 314 301 end 315 if kind == 'p' then316 local s = prep(fp)317 closefile(fp)318 return s319 end320 302 local s = read(fp,'*a') 321 303 closefile(fp) 322 304 if kind == 'c' or kind == 'h' then 323 305 return extract_code(fn,s) 306 elseif kind == 'p' then 307 return "\n\n" .. s 324 308 elseif kind == 'l' then 325 309 return "\n$[--##"..fn.."\n" .. s .. "\n$]\n" … … 353 337 354 338 355 setmetatable(_extra_parameters, { __index = _G })356 357 function prep(file)358 359 local chunk = {'local __ret = {"\\n"}\n'}360 for line in file:lines() do361 if string.find(line, "^##") then362 table.insert(chunk, string.sub(line, 3) .. "\n")363 else364 local last = 1365 for text, expr, index in string.gfind(line, "(.-)$(%b())()") do366 last = index367 if text ~= "" then368 table.insert(chunk, string.format('table.insert(__ret, %q )', text))369 end370 table.insert(chunk, string.format('table.insert(__ret, %s )', expr))371 end372 table.insert(chunk, string.format('table.insert(__ret, %q)\n',373 string.sub(line, last).."\n"))374 end375 end376 table.insert(chunk, '\nreturn table.concat(__ret)\n')377 local f,e = loadstring(table.concat(chunk))378 if e then379 error("#"..e)380 end381 setfenv(f, _extra_parameters)382 return f()383 end -
code/branches/pch/src/tolua/lua/variable.lua
r3127 r3138 109 109 if string.find(self.mod, 'tolua_property') then 110 110 111 local_,_,type = string.find(self.mod, "tolua_property__([^%s]*)")111 _,_,type = string.find(self.mod, "tolua_property__([^%s]*)") 112 112 type = type or "default" 113 113 prop_get,prop_set = get_property_methods(type, self.name) … … 131 131 output(' ',self.parent.type,'*','self = ') 132 132 output('(',self.parent.type,'*) ') 133 local to_func = get_to_function(self.parent.type) 134 output(to_func,'(tolua_S,1,0);') 133 output('tolua_tousertype(tolua_S,1,0);') 135 134 elseif static then 136 135 _,_,self.mod = strfind(self.mod,'^%s*static%s%s*(.*)') … … 141 140 if class and static==nil then 142 141 output('#ifndef TOLUA_RELEASE\n') 143 output(' if (!self) tolua_error(tolua_S," '..output_error_hook("invalid \'self\' in accessing variable \'%s\'", self.name)..'",NULL);');142 output(' if (!self) tolua_error(tolua_S,"invalid \'self\' in accessing variable \''..self.name..'\'",NULL);'); 144 143 output('#endif\n') 145 144 end … … 147 146 -- return value 148 147 if string.find(self.mod, 'tolua_inherits') then 149 local push_func = get_push_function(self.type)150 148 output('#ifdef __cplusplus\n') 151 output(' ',push_func,'(tolua_S,(void*)static_cast<'..self.type..'*>(self), "',self.type,'");')149 output(' tolua_pushusertype(tolua_S,(void*)static_cast<'..self.type..'*>(self), "',self.type,'");') 152 150 output('#else\n') 153 output(' ',push_func,'(tolua_S,(void*)(('..self.type..'*)self), "',self.type,'");')151 output(' tolua_pushusertype(tolua_S,(void*)(('..self.type..'*)self), "',self.type,'");') 154 152 output('#endif\n') 155 153 else … … 158 156 output(' tolua_push'..t..'(tolua_S,(',ct,')'..self:getvalue(class,static,prop_get)..');') 159 157 else 160 local push_func = get_push_function(self.type)161 158 t = self.type 162 159 if self.ptr == '&' or self.ptr == '' then 163 output(' ',push_func,'(tolua_S,(void*)&'..self:getvalue(class,static,prop_get)..',"',t,'");')164 else 165 output(' ',push_func,'(tolua_S,(void*)'..self:getvalue(class,static,prop_get)..',"',t,'");')160 output(' tolua_pushusertype(tolua_S,(void*)&'..self:getvalue(class,static,prop_get)..',"',t,'");') 161 else 162 output(' tolua_pushusertype(tolua_S,(void*)'..self:getvalue(class,static,prop_get)..',"',t,'");') 166 163 end 167 164 end … … 188 185 output(' ',self.parent.type,'*','self = ') 189 186 output('(',self.parent.type,'*) ') 190 local to_func = get_to_function(self.parent.type) 191 output(to_func,'(tolua_S,1,0);') 187 output('tolua_tousertype(tolua_S,1,0);') 192 188 -- check self value 193 189 end … … 196 192 output(' tolua_Error tolua_err;') 197 193 if class and static==nil then 198 output(' if (!self) tolua_error(tolua_S," '..output_error_hook("invalid \'self\' in accessing variable \'%s\'", self.name)..'",NULL);');194 output(' if (!self) tolua_error(tolua_S,"invalid \'self\' in accessing variable \''..self.name..'\'",NULL);'); 199 195 elseif static then 200 196 _,_,self.mod = strfind(self.mod,'^%s*static%s%s*(.*)') … … 202 198 203 199 -- check variable type 204 output(' if ( '..self:outchecktype(2)..')')200 output(' if (!'..self:outchecktype(2)..')') 205 201 output(' tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err);') 206 202 output('#endif\n') … … 210 206 if self.def ~= '' then def = self.def end 211 207 if self.type == 'char*' and self.dim ~= '' then -- is string 212 output(' strncpy( (char*)')208 output(' strncpy(') 213 209 if class and static then 214 210 output(self.parent.type..'::'..self.name) … … 218 214 output(self.name) 219 215 end 220 output(', (const char*)tolua_tostring(tolua_S,2,',def,'),',self.dim,'-1);')216 output(',tolua_tostring(tolua_S,2,',def,'),',self.dim,'-1);') 221 217 else 222 218 local ptr = '' … … 249 245 output('tolua_to'..t,'(tolua_S,2,',def,'))') 250 246 else 251 local to_func = get_to_function(self.type) 252 output(to_func,'(tolua_S,2,',def,'))') 247 output('tolua_tousertype(tolua_S,2,',def,'))') 253 248 end 254 249 if prop_set then
Note: See TracChangeset
for help on using the changeset viewer.