主頁 > 知識(shí)庫 > 使用lua實(shí)現(xiàn)php的var_dump()函數(shù)功能

使用lua實(shí)現(xiàn)php的var_dump()函數(shù)功能

熱門標(biāo)簽:Linux服務(wù)器 百度競價(jià)排名 鐵路電話系統(tǒng) 地方門戶網(wǎng)站 網(wǎng)站排名優(yōu)化 呼叫中心市場需求 AI電銷 服務(wù)外包

習(xí)慣了php中的var_dump()函數(shù),而如今寫lua的時(shí)候總習(xí)慣使用var_dump()函數(shù),于是就自己動(dòng)手寫了一個(gè)類似功能的var_dump()函數(shù)。

復(fù)制代碼 代碼如下:

function var_dump(data, max_level, prefix)  
    if type(prefix) ~= "string" then  
        prefix = "" 
    end  
    if type(data) ~= "table" then  
        print(prefix .. tostring(data))  
    else 
        print(data)  
        if max_level ~= 0 then  
            local prefix_next = prefix .. "    " 
            print(prefix .. "{")  
            for k,v in pairs(data) do 
                io.stdout:write(prefix_next .. k .. " = ")  
                if type(v) ~= "table" or (type(max_level) == "number" and max_level = 1) then  
                    print(v)  
                else 
                    if max_level == nil then  
                        var_dump(v, nil, prefix_next)  
                    else 
                        var_dump(v, max_level - 1, prefix_next)  
                    end  
                end  
            end  
            print(prefix .. "}")  
        end  
    end  
end 

您可能感興趣的文章:
  • 獲取Lua表結(jié)構(gòu)(table)數(shù)據(jù)實(shí)例
  • Lua極簡入門指南:全局變量
  • Lua極簡入門指南(六):模塊
  • Lua中實(shí)現(xiàn)StringBuffer功能
  • lua獲取未來某時(shí)間點(diǎn)的時(shí)間戳解決方案

標(biāo)簽:湘潭 湖南 衡水 銅川 黃山 蘭州 崇左 仙桃

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《使用lua實(shí)現(xiàn)php的var_dump()函數(shù)功能》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266