Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 9, 2009, 4:29:42 PM (16 years ago)
Author:
rgrieder
Message:

Update to tolua 1.0.93

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pch/src/tolua/lua/function.lua

    r2710 r3127  
    209209    if class then narg=2 else narg=1 end
    210210    if class then
    211         local func = 'tolua_isusertype'
     211        local func = get_is_function(self.parent.type)
    212212        local type = self.parent.type
    213213        if self.name=='new' or static~=nil then
     
    226226            local btype = isbasic(self.args[i].type)
    227227            if btype ~= 'value' and btype ~= 'state' then
    228                 output('     !'..self.args[i]:outchecktype(narg)..' ||\n')
     228                output('     '..self.args[i]:outchecktype(narg)..' ||\n')
    229229            end
    230230            if btype ~= 'state' then
     
    250250        output(' ',self.const,self.parent.type,'*','self = ')
    251251        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);')
    253254    elseif static then
    254255        _,_,self.mod = strfind(self.mod,'^%s*static%s%s*(.*)')
     
    269270    if class and self.name~='new' and static==nil then
    270271        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);');
    272273        output('#endif\n')
    273274    end
     
    312313    --------------------------------------------------
    313314
     315    pre_call_hook(self)
     316
    314317    local out = string.find(self.mod, "tolua_outside")
    315318
     
    323326    -- call function
    324327    if class and self.name=='delete' then
    325         output('  delete self;')
     328        output('  Mtolua_delete(self);')
    326329    elseif class and self.name == 'operator&[]' then
    327330        if flags['1'] then -- for compatibility with tolua5 ?
     
    352355    end
    353356    if class and self.name=='new' then
    354         output('new',self.type,'(')
     357        output('Mtolua_new((',self.type,')(')
    355358    elseif class and static then
    356359        if out then
     
    364367        else
    365368            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,'(')
    367371            else
    368372                output('self->'..self.name,'(')
     
    392396        output('-1);')
    393397    else
    394         output(');')
     398        if class and self.name=='new' then
     399            output('));') -- close Mtolua_new(
     400        else
     401            output(');')
     402        end
    395403    end
    396404
     
    399407        nret = nret + 1
    400408        local t,ct = isbasic(self.type)
    401         if t then
     409        if t and self.name ~= "new" then
    402410            if self.cast_operator and _basic_raw_push[t] then
    403411                output('   ',_basic_raw_push[t],'(tolua_S,(',ct,')tolua_ret);')
     
    408416                t = self.type
    409417                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)
    410423                if self.ptr == '' then
    411424                    output('   {')
    412425                    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));')
    415429                    output('#else\n')
    416430                    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));')
    418433                    output('#endif\n')
    419434                    output('   }')
    420435                elseif self.ptr == '&' then
    421                     output('   tolua_pushusertype(tolua_S,(void*)&tolua_ret,"',t,'");')
     436                    output('   ',push_func,'(tolua_S,(void*)&tolua_ret,"',t,'");')
    422437                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));')
    427441                    end
    428442                end
     
    466480    end
    467481
     482    post_call_hook(self)
     483
    468484    output(' }')
    469485    output(' return '..nret..';')
     
    474490        output('#ifndef TOLUA_RELEASE\n')
    475491        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);')
    477493        output(' return 0;')
    478494        output('#endif\n')
     
    574590    if string.find(par, "%*") then -- it's a pointer with a default value
    575591
    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?
    577593            return true
    578594        end
     
    661677        --ns = strip_defaults(ns)
    662678
    663         Function(d, ns, c)
     679        local f = Function(d, ns, c)
    664680        for i=1,last do
    665681            t[i] = string.gsub(t[i], "=.*$", "")
Note: See TracChangeset for help on using the changeset viewer.