Changeset 3138 for code/branches/pch/src/tolua/lua/function.lua
- Timestamp:
- Jun 10, 2009, 4:01:42 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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], "=.*$", "")
Note: See TracChangeset
for help on using the changeset viewer.