当前位置 : 主页 > 手机开发 > 其它 >

[cocos2dx_Lua]打印用户数据

来源:互联网 收集:自由互联 发布时间:2021-06-13
local m = {}function m:printTT(content, ...) local tab = 0 local out_list = {} local function printk(value, key, tab) if key == nil then return end if type(key) ~= "number" then key = tostring(key) else key = string.format("[%d]", key) end


local m = {}
function m:printTT(content, ...)
    local tab = 0
    local out_list = {}

    local function printk(value, key, tab)
        if key == nil then
            return
        end
        if type(key) ~= "number" then
            key = tostring(key)
        else
            key = string.format("[%d]", key)
        end
        if type(value) == "table" then
            if key ~= nil then
                table.insert(out_list, tab .. key .. " =")
            end
            table.insert(out_list, tab .. "{")
            for k, v in pairs(value) do
                printk(v, k, tab .. "|  ")
            end
            table.insert(out_list, tab .. "},")
        else
            local content
            if type(value) == "nil" or value == "^&nil" then
                value = "nil"
            elseif type(value) == "string" then
                value = string.format("\"%s\"", tostring(value))
            else
                value = tostring(value)
            end
            content = string.format("%s%s = %s,", tab, key, value)
            table.insert(out_list, tostring(content))
        end
    end
    local value = type(content) == "string" and string.format(content, ...) or content
    local key = os.date("[\"%X\"]", os.time())
    printk(value, key, "")

    local out_str = table.concat(out_list, "\n")
    print(out_str .. "\n")

    -- local logFileName = os.date("print_tab_%Y_%m_%d.log", os.time())
    -- local logFileName = "a.log"
    -- local file = assert(io.open(logFileName, "a+"))
    -- file:write(out_str .. "\n")
    -- file:close()
end

--打印用户数据
function m:logUD(ud)
    local function tmp(metaT,dSet)  
        if metaT then
            for _val, _val_type in pairs(metaT) do
                if type(_val_type) ~= "userdata" then   
                    if not string.find(_val,"_") then                  
                        table.insert(dSet,_val)  
                    end        
                end  
            end
            table.sort(dSet)
            dSet[tostring(metaT)] = {}
            tmp(getmetatable(metaT),dSet[tostring(metaT)])      
        end  
    end
    local resTb = {}
    tmp(getmetatable(ud),resTb)
    m:printTT(resTb)
end
return m

打印结果

[LUA-print] ["21:06:18"] =
{
|  [1] = ".backup",
|  [2] = "create",
|  [3] = "createInstance",
|  [4] = "disableEffect",
|  [5] = "enableGlow",
|  [6] = "enableOutline",
|  [7] = "enableShadow",
|  [8] = "getAutoRenderSize",
|  [9] = "getEffectColor",
|  [10] = "getFontName",
|  [11] = "getFontSize",
|  [12] = "getLabelEffectType",
|  [13] = "getOutlineSize",
|  [14] = "getShadowBlurRadius",
|  [15] = "getShadowColor",
|  [16] = "getShadowOffset",
|  [17] = "getString",
|  [18] = "getStringLength",
|  [19] = "getStringValue",
|  [20] = "getTextAreaSize",
|  [21] = "getTextColor",
|  [22] = "getTextHorizontalAlignment",
|  [23] = "getTextVerticalAlignment",
|  [24] = "getType",
|  [25] = "init",
|  [26] = "isShadowEnabled",
|  [27] = "isTouchScaleChangeEnabled",
|  [28] = "new",
|  [29] = "setFontName",
|  [30] = "setFontSize",
|  [31] = "setString",
|  [32] = "setText",
|  [33] = "setTextAreaSize",
|  [34] = "setTextColor",
|  [35] = "setTextHorizontalAlignment",
|  [36] = "setTextVerticalAlignment",
|  [37] = "setTouchScaleChangeEnabled",
|  table: 0x010d7ebef0 =
|  {
|  |  [1] = "addClickEventListener",
|  |  [2] = "addTouchEventListener",
|  |  [3] = "clone",
|  |  [4] = "create",
|  |  [5] = "dispatchFocusEvent",
|  |  [6] = "enableDpadNavigation",
|  |  [7] = "findNextFocusedWidget",
|  |  [8] = "getActionTag",
|  |  [9] = "getBottomBoundary",
|  |  [10] = "getBottomInParent",
|  |  [11] = "getCallbackName",
|  |  [12] = "getCallbackType",
|  |  [13] = "getCurrentFocusedWidget",
|  |  [14] = "getCustomSize",
|  |  [15] = "getLayoutParameter",
|  |  [16] = "getLayoutSize",
|  |  [17] = "getLeftBoundary",
|  |  [18] = "getLeftInParent",
|  |  [19] = "getPositionPercent",
|  |  [20] = "getPositionType",
|  |  [21] = "getRightBoundary",
|  |  [22] = "getRightInParent",
|  |  [23] = "getSize",
|  |  [24] = "getSizePercent",
|  |  [25] = "getSizeType",
|  |  [26] = "getTopBoundary",
|  |  [27] = "getTopInParent",
|  |  [28] = "getTouchBeganPosition",
|  |  [29] = "getTouchEndPosition",
|  |  [30] = "getTouchMovePosition",
|  |  [31] = "getVirtualRenderer",
|  |  [32] = "getVirtualRendererSize",
|  |  [33] = "getWorldPosition",
|  |  [34] = "hitTest",
|  |  [35] = "ignoreContentAdaptWithSize",
|  |  [36] = "interceptTouchEvent",
|  |  [37] = "isBright",
|  |  [38] = "isClippingParentContainsPoint",
|  |  [39] = "isEnabled",
|  |  [40] = "isFlippedX",
|  |  [41] = "isFlippedY",
|  |  [42] = "isFocusEnabled",
|  |  [43] = "isFocused",
|  |  [44] = "isHighlighted",
|  |  [45] = "isIgnoreContentAdaptWithSize",
|  |  [46] = "isLayoutComponentEnabled",
|  |  [47] = "isPropagateTouchEvents",
|  |  [48] = "isSwallowTouches",
|  |  [49] = "isTouchEnabled",
|  |  [50] = "isUnifySizeEnabled",
|  |  [51] = "new",
|  |  [52] = "onFocusChange",
|  |  [53] = "onTouch",
|  |  [54] = "propagateTouchEvent",
|  |  [55] = "requestFocus",
|  |  [56] = "setActionTag",
|  |  [57] = "setBright",
|  |  [58] = "setBrightStyle",
|  |  [59] = "setCallbackName",
|  |  [60] = "setCallbackType",
|  |  [61] = "setEnabled",
|  |  [62] = "setFlippedX",
|  |  [63] = "setFlippedY",
|  |  [64] = "setFocusEnabled",
|  |  [65] = "setFocused",
|  |  [66] = "setHighlighted",
|  |  [67] = "setLayoutComponentEnabled",
|  |  [68] = "setLayoutParameter",
|  |  [69] = "setPositionPercent",
|  |  [70] = "setPositionType",
|  |  [71] = "setPropagateTouchEvents",
|  |  [72] = "setSize",
|  |  [73] = "setSizePercent",
|  |  [74] = "setSizeType",
|  |  [75] = "setSwallowTouches",
|  |  [76] = "setTouchEnabled",
|  |  [77] = "setUnifySizeEnabled",
|  |  [78] = "updateSizeAndPosition",
|  |  table: 0x010d7bcd18 =
|  |  {
|  |  |  [1] = "addProtectedChild",
|  |  |  [2] = "create",
|  |  |  [3] = "disableCascadeColor",
|  |  |  [4] = "disableCascadeOpacity",
|  |  |  [5] = "getProtectedChildByTag",
|  |  |  [6] = "new",
|  |  |  [7] = "removeAllProtectedChildren",
|  |  |  [8] = "removeAllProtectedChildrenWithCleanup",
|  |  |  [9] = "removeProtectedChild",
|  |  |  [10] = "removeProtectedChildByTag",
|  |  |  [11] = "reorderProtectedChild",
|  |  |  [12] = "sortAllProtectedChildren",
|  |  |  table: 0x010d6e0db0 =
|  |  |  {
|  |  |  |  [1] = "add",
|  |  |  |  [2] = "addChild",
|  |  |  |  [3] = "addComponent",
|  |  |  |  [4] = "addTo",
|  |  |  |  [5] = "align",
|  |  |  |  [6] = "boundingBox",
|  |  |  |  [7] = "cleanup",
|  |  |  |  [8] = "convertToNodeSpace",
|  |  |  |  [9] = "convertToNodeSpaceAR",
|  |  |  |  [10] = "convertToWorldSpace",
|  |  |  |  [11] = "convertToWorldSpaceAR",
|  |  |  |  [12] = "convertTouchToNodeSpace",
|  |  |  |  [13] = "convertTouchToNodeSpaceAR",
|  |  |  |  [14] = "create",
|  |  |  |  [15] = "disableNodeEvents",
|  |  |  |  [16] = "draw",
|  |  |  |  [17] = "enableNodeEvents",
|  |  |  |  [18] = "enumerateChildren",
|  |  |  |  [19] = "fadeIn",
|  |  |  |  [20] = "fadeOut",
|  |  |  |  [21] = "fadeTo",
|  |  |  |  [22] = "getActionByTag",
|  |  |  |  [23] = "getActionManager",
|  |  |  |  [24] = "getAnchorPoint",
|  |  |  |  [25] = "getAnchorPointInPoints",
|  |  |  |  [26] = "getBoundingBox",
|  |  |  |  [27] = "getCameraMask",
|  |  |  |  [28] = "getChildByName",
|  |  |  |  [29] = "getChildByTag",
|  |  |  |  [30] = "getChildren",
|  |  |  |  [31] = "getChildrenCount",
|  |  |  |  [32] = "getColor",
|  |  |  |  [33] = "getComponent",
|  |  |  |  [34] = "getContentSize",
|  |  |  |  [35] = "getDescription",
|  |  |  |  [36] = "getDisplayedColor",
|  |  |  |  [37] = "getDisplayedOpacity",
|  |  |  |  [38] = "getEventDispatcher",
|  |  |  |  [39] = "getGLProgram",
|  |  |  |  [40] = "getGLProgramState",
|  |  |  |  [41] = "getGlobalZOrder",
|  |  |  |  [42] = "getLocalZOrder",
|  |  |  |  [43] = "getName",
|  |  |  |  [44] = "getNodeToParentAffineTransform",
|  |  |  |  [45] = "getNodeToParentTransform",
|  |  |  |  [46] = "getNodeToWorldAffineTransform",
|  |  |  |  [47] = "getNodeToWorldTransform",
|  |  |  |  [48] = "getNormalizedPosition",
|  |  |  |  [49] = "getNumberOfRunningActions",
|  |  |  |  [50] = "getOpacity",
|  |  |  |  [51] = "getOrderOfArrival",
|  |  |  |  [52] = "getParent",
|  |  |  |  [53] = "getParentToNodeAffineTransform",
|  |  |  |  [54] = "getParentToNodeTransform",
|  |  |  |  [55] = "getPhysicsBody",
|  |  |  |  [56] = "getPosition",
|  |  |  |  [57] = "getPosition3D",
|  |  |  |  [58] = "getPositionX",
|  |  |  |  [59] = "getPositionY",
|  |  |  |  [60] = "getPositionZ",
|  |  |  |  [61] = "getRotation",
|  |  |  |  [62] = "getRotation3D",
|  |  |  |  [63] = "getRotationSkewX",
|  |  |  |  [64] = "getRotationSkewY",
|  |  |  |  [65] = "getScale",
|  |  |  |  [66] = "getScaleX",
|  |  |  |  [67] = "getScaleY",
|  |  |  |  [68] = "getScaleZ",
|  |  |  |  [69] = "getScene",
|  |  |  |  [70] = "getScheduler",
|  |  |  |  [71] = "getSkewX",
|  |  |  |  [72] = "getSkewY",
|  |  |  |  [73] = "getTag",
|  |  |  |  [74] = "getVertexZ",
|  |  |  |  [75] = "getWorldToNodeAffineTransform",
|  |  |  |  [76] = "getWorldToNodeTransform",
|  |  |  |  [77] = "getZOrder",
|  |  |  |  [78] = "hide",
|  |  |  |  [79] = "ignoreAnchorPointForPosition",
|  |  |  |  [80] = "init",
|  |  |  |  [81] = "isCascadeColorEnabled",
|  |  |  |  [82] = "isCascadeOpacityEnabled",
|  |  |  |  [83] = "isIgnoreAnchorPointForPosition",
|  |  |  |  [84] = "isOpacityModifyRGB",
|  |  |  |  [85] = "isRunning",
|  |  |  |  [86] = "isScheduled",
|  |  |  |  [87] = "isVisible",
|  |  |  |  [88] = "move",
|  |  |  |  [89] = "moveBy",
|  |  |  |  [90] = "moveTo",
|  |  |  |  [91] = "new",
|  |  |  |  [92] = "numberOfRunningActions",
|  |  |  |  [93] = "onCleanup",
|  |  |  |  [94] = "onEnter",
|  |  |  |  [95] = "onEnterTransitionFinish",
|  |  |  |  [96] = "onExit",
|  |  |  |  [97] = "onExitTransitionStart",
|  |  |  |  [98] = "onNodeEvent",
|  |  |  |  [99] = "onUpdate",
|  |  |  |  [100] = "pause",
|  |  |  |  [101] = "registerScriptHandler",
|  |  |  |  [102] = "removeAllChildren",
|  |  |  |  [103] = "removeAllComponents",
|  |  |  |  [104] = "removeChild",
|  |  |  |  [105] = "removeChildByName",
|  |  |  |  [106] = "removeChildByTag",
|  |  |  |  [107] = "removeComponent",
|  |  |  |  [108] = "removeFromParent",
|  |  |  |  [109] = "removeFromParentAndCleanup",
|  |  |  |  [110] = "removeSelf",
|  |  |  |  [111] = "reorderChild",
|  |  |  |  [112] = "resume",
|  |  |  |  [113] = "rotate",
|  |  |  |  [114] = "rotateBy",
|  |  |  |  [115] = "rotateTo",
|  |  |  |  [116] = "runAction",
|  |  |  |  [117] = "scaleTo",
|  |  |  |  [118] = "scheduleUpdate",
|  |  |  |  [119] = "scheduleUpdateWithPriorityLua",
|  |  |  |  [120] = "setActionManager",
|  |  |  |  [121] = "setAdditionalTransform",
|  |  |  |  [122] = "setAnchorPoint",
|  |  |  |  [123] = "setCameraMask",
|  |  |  |  [124] = "setCascadeColorEnabled",
|  |  |  |  [125] = "setCascadeOpacityEnabled",
|  |  |  |  [126] = "setColor",
|  |  |  |  [127] = "setContentSize",
|  |  |  |  [128] = "setEventDispatcher",
|  |  |  |  [129] = "setGLProgram",
|  |  |  |  [130] = "setGLProgramState",
|  |  |  |  [131] = "setGlobalZOrder",
|  |  |  |  [132] = "setLocalZOrder",
|  |  |  |  [133] = "setName",
|  |  |  |  [134] = "setNodeToParentTransform",
|  |  |  |  [135] = "setNormalizedPosition",
|  |  |  |  [136] = "setOnEnterCallback",
|  |  |  |  [137] = "setOnExitCallback",
|  |  |  |  [138] = "setOpacity",
|  |  |  |  [139] = "setOpacityModifyRGB",
|  |  |  |  [140] = "setOrderOfArrival",
|  |  |  |  [141] = "setParent",
|  |  |  |  [142] = "setPhysicsBody",
|  |  |  |  [143] = "setPosition",
|  |  |  |  [144] = "setPosition3D",
|  |  |  |  [145] = "setPositionX",
|  |  |  |  [146] = "setPositionY",
|  |  |  |  [147] = "setPositionZ",
|  |  |  |  [148] = "setRotation",
|  |  |  |  [149] = "setRotation3D",
|  |  |  |  [150] = "setRotationQuat",
|  |  |  |  [151] = "setRotationSkewX",
|  |  |  |  [152] = "setRotationSkewY",
|  |  |  |  [153] = "setScale",
|  |  |  |  [154] = "setScaleX",
|  |  |  |  [155] = "setScaleY",
|  |  |  |  [156] = "setScaleZ",
|  |  |  |  [157] = "setScheduler",
|  |  |  |  [158] = "setSkewX",
|  |  |  |  [159] = "setSkewY",
|  |  |  |  [160] = "setTag",
|  |  |  |  [161] = "setUserObject",
|  |  |  |  [162] = "setVertexZ",
|  |  |  |  [163] = "setVisible",
|  |  |  |  [164] = "setZOrder",
|  |  |  |  [165] = "setonEnterTransitionDidFinishCallback",
|  |  |  |  [166] = "setonExitTransitionDidStartCallback",
|  |  |  |  [167] = "show",
|  |  |  |  [168] = "sortAllChildren",
|  |  |  |  [169] = "stopAction",
|  |  |  |  [170] = "stopActionByTag",
|  |  |  |  [171] = "stopActionsByFlags",
|  |  |  |  [172] = "stopAllActions",
|  |  |  |  [173] = "stopAllActionsByTag",
|  |  |  |  [174] = "unregisterScriptHandler",
|  |  |  |  [175] = "unscheduleUpdate",
|  |  |  |  [176] = "update",
|  |  |  |  [177] = "updateDisplayedColor",
|  |  |  |  [178] = "updateDisplayedOpacity",
|  |  |  |  [179] = "updateTransform",
|  |  |  |  [180] = "visit",
|  |  |  |  table: 0x010c765d50 =
|  |  |  |  {
|  |  |  |  |  [1] = "getReferenceCount",
|  |  |  |  |  [2] = "release",
|  |  |  |  |  [3] = "retain",
|  |  |  |  |  table: 0x010c76cf18 =
|  |  |  |  |  {
|  |  |  |  |  |  table: 0x010c76d208 =
|  |  |  |  |  |  {
|  |  |  |  |  |  },
|  |  |  |  |  },
|  |  |  |  },
|  |  |  },
|  |  },
|  },
},
网友评论