Changeset 3127 for code/branches/pch/src/tolua/lua/function.lua
- Timestamp:
- Jun 9, 2009, 4:29:42 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pch/src/tolua/lua/function.lua
r2710 r3127 209 209 if class then narg=2 else narg=1 end 210 210 if class then 211 local func = 'tolua_isusertype'211 local func = get_is_function(self.parent.type) 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 output('tolua_tousertype(tolua_S,1,0);') 252 local to_func = get_to_function(self.parent.type) 253 output(to_func,'(tolua_S,1,0);') 253 254 elseif static then 254 255 _,_,self.mod = strfind(self.mod,'^%s*static%s%s*(.*)') … … 269 270 if class and self.name~='new' and static==nil then 270 271 output('#ifndef TOLUA_RELEASE\n') 271 output(' if (!self) tolua_error(tolua_S," invalid \'self\' in function \''..self.name..'\'",NULL);');272 output(' if (!self) tolua_error(tolua_S,"'..output_error_hook("invalid \'self\' in function \'%s\'", self.name)..'", NULL);'); 272 273 output('#endif\n') 273 274 end … … 312 313 -------------------------------------------------- 313 314 315 pre_call_hook(self) 316 314 317 local out = string.find(self.mod, "tolua_outside") 315 318 … … 323 326 -- call function 324 327 if class and self.name=='delete' then 325 output(' delete self;')328 output(' Mtolua_delete(self);') 326 329 elseif class and self.name == 'operator&[]' then 327 330 if flags['1'] then -- for compatibility with tolua5 ? … … 352 355 end 353 356 if class and self.name=='new' then 354 output(' new',self.type,'(')357 output('Mtolua_new((',self.type,')(') 355 358 elseif class and static then 356 359 if out then … … 364 367 else 365 368 if self.cast_operator then 366 output('static_cast<',self.mod,self.type,self.ptr,'>(*self') 369 --output('static_cast<',self.mod,self.type,self.ptr,' >(*self') 370 output('self->operator ',self.mod,self.type,'(') 367 371 else 368 372 output('self->'..self.name,'(') … … 392 396 output('-1);') 393 397 else 394 output(');') 398 if class and self.name=='new' then 399 output('));') -- close Mtolua_new( 400 else 401 output(');') 402 end 395 403 end 396 404 … … 399 407 nret = nret + 1 400 408 local t,ct = isbasic(self.type) 401 if t then409 if t and self.name ~= "new" then 402 410 if self.cast_operator and _basic_raw_push[t] then 403 411 output(' ',_basic_raw_push[t],'(tolua_S,(',ct,')tolua_ret);') … … 408 416 t = self.type 409 417 new_t = string.gsub(t, "const%s+", "") 418 local owned = false 419 if string.find(self.mod, "tolua_owned") then 420 owned = true 421 end 422 local push_func = get_push_function(t) 410 423 if self.ptr == '' then 411 424 output(' {') 412 425 output('#ifdef __cplusplus\n') 413 output(' void* tolua_obj = new',new_t,'(tolua_ret);') 414 output(' tolua_pushusertype_and_takeownership(tolua_S,tolua_obj,"',t,'");') 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));') 415 429 output('#else\n') 416 430 output(' void* tolua_obj = tolua_copy(tolua_S,(void*)&tolua_ret,sizeof(',t,'));') 417 output(' tolua_pushusertype_and_takeownership(tolua_S,tolua_obj,"',t,'");') 431 output(' ',push_func,'(tolua_S,tolua_obj,"',t,'");') 432 output(' tolua_register_gc(tolua_S,lua_gettop(tolua_S));') 418 433 output('#endif\n') 419 434 output(' }') 420 435 elseif self.ptr == '&' then 421 output(' tolua_pushusertype(tolua_S,(void*)&tolua_ret,"',t,'");')436 output(' ',push_func,'(tolua_S,(void*)&tolua_ret,"',t,'");') 422 437 else 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,'");') 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));') 427 441 end 428 442 end … … 466 480 end 467 481 482 post_call_hook(self) 483 468 484 output(' }') 469 485 output(' return '..nret..';') … … 474 490 output('#ifndef TOLUA_RELEASE\n') 475 491 output('tolua_lerror:\n') 476 output(' tolua_error(tolua_S," #ferror in function \''..self.lname..'\'.",&tolua_err);')492 output(' tolua_error(tolua_S,"'..output_error_hook("#ferror in function \'%s\'.", self.lname)..'",&tolua_err);') 477 493 output(' return 0;') 478 494 output('#endif\n') … … 574 590 if string.find(par, "%*") then -- it's a pointer with a default value 575 591 576 if string.find(par, '=%s*new') then -- it's a pointer with an instance as default parameter.. is that valid?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? 577 593 return true 578 594 end … … 661 677 --ns = strip_defaults(ns) 662 678 663 Function(d, ns, c)679 local f = Function(d, ns, c) 664 680 for i=1,last do 665 681 t[i] = string.gsub(t[i], "=.*$", "")
Note: See TracChangeset
for help on using the changeset viewer.