美文网首页
0905 - lite 更好的调试 2

0905 - lite 更好的调试 2

作者: 自由快挂 | 来源:发表于2017-09-05 21:57 被阅读19次

    《lite 更好的调试》 的实现有些不对劲,流程不对,实现依赖了 cocos 的包和框架,导致出现问题时,不能在模拟器中显示错误。解决如下:

    1. __G__TRACKBACK__ 函数里面只包括 c++ 导出的方法
    2. 所以的 require 都放到 main 函数里面去,就能够处理框架内的错误了
    local STP = require "StackTracePlus"
    local _traceback = debug.traceback
    debug.traceback = STP.stacktrace
    
    local winsize = cc.Director:getInstance():getWinSize()
    local target = cc.Application:getInstance():getTargetPlatform()
    __G__TRACKBACK__ = function ( msg )
    
        local message = msg
        local msg, origin_error = debug.traceback(msg, 3)
        print(msg)
    
        -- report lua exception
        if target == 4 or target == 5 then -- ios
            buglyReportLuaException(tostring(message), _traceback())
        elseif target == 2 then -- mac
            local msg = debug.getinfo(2)
            local info = cc.Label:createWithSystemFont(message, 'sans', 32)
            info:setWidth(winsize.width)
            info:setAnchorPoint({x=0,y=1})
            info:setPosition(0, winsize.height)
            info:setTextColor({r=255,g=0,b=0,a=255})
    
            local scene = cc.Director:getInstance():getRunningScene()
            if scene then
                scene:addChild(info, 998)
            else
                scene = cc.Scene:create()
                scene:addChild(info)
                cc.Director:getInstance():runWithScene(scene)
            end
    
            local function onTouchBegan(touch, event)
                return true
            end
            local function onTouchEnded(touch, event)
                os.execute(string.format('subl %s:%d', cc.FileUtils:getInstance():fullPathForFilename(msg.source), msg.currentline))
                info:removeSelf()
            end
    
            local listener = cc.EventListenerTouchOneByOne:create()
            listener:registerScriptHandler(onTouchBegan,40)--cc.Handler.EVENT_TOUCH_BEGAN
            listener:registerScriptHandler(onTouchEnded,42)--cc.Handler.EVENT_TOUCH_ENDED
            local eventDispatcher = info:getEventDispatcher()
            eventDispatcher:addEventListenerWithSceneGraphPriority(listener, info)
        end
    
        return msg
    end
    
    local function main()
        require "config"
        require "cocos.init"
    
        require 'pack'
        require 'pbc.pbc'
        if CC_REMOTE_DEBUG then
            require('mobdebug').start()
        end
    
        local app = require('app.App'):instance()
        app:run('LoginController')
    end
    
    local status, msg = xpcall(main, __G__TRACKBACK__)
    if not status then
        print(msg)
    end
    

    相关文章

      网友评论

          本文标题:0905 - lite 更好的调试 2

          本文链接:https://www.haomeiwen.com/subject/kovpjxtx.html