国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

使用lua實現php的print_r()函數功能

2024-07-21 23:04:17
字體:
來源:轉載
供稿:網友

之前寫了一些類似php的函數,下面再來一個print_r()函數,代碼如下:

 

復制代碼 代碼如下:

function pr (t, name, indent)  
    local tableList = {}  
    function table_r (t, name, indent, full)  
        local id = not full and name or type(name)~="number" and tostring(name) or '['..name..']'  
        local tag = indent .. id .. ' = '  
        local out = {}  -- result  
        if type(t) == "table" then  
            if tableList[t] ~= nil then  
                table.insert(out, tag .. '{} -- ' .. tableList[t] .. ' (self reference)')  
            else 
                tableList[t]= full and (full .. '.' .. id) or id 
                if next(t) then -- Table not empty  
                    table.insert(out, tag .. '{')  
                    for key,value in pairs(t) do  
                        table.insert(out,table_r(value,key,indent .. '|  ',tableList[t]))  
                    end  
                    table.insert(out,indent .. '}')  
                else table.insert(out,tag .. '{}') end  
            end  
        else 
            local val = type(t)~="number" and type(t)~="boolean" and '"'..tostring(t)..'"' or tostring(t)  
            table.insert(out, tag .. val)  
        end  
        return table.concat(out, '/n')  
    end  
    return table_r(t,name or 'Value',indent or '')  
end  
function print_r (t, name)  
    print(pr(t,name))  
end  
 
local a = {x=1, y=2, label={text='hans', color='blue'}, list={'a','b','c'}}  
 
print_r(a) 
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 四平市| 深泽县| 罗田县| 若羌县| 巩留县| 永登县| 同仁县| 龙江县| 增城市| 峨山| 黄浦区| 永福县| 中方县| 德保县| 镇平县| 商水县| 怀宁县| 乌拉特后旗| 西畴县| 万全县| 岐山县| 西乌珠穆沁旗| 眉山市| 托克逊县| 兴化市| 松潘县| 正定县| 石家庄市| 安乡县| 舞钢市| 怀宁县| 延边| 安平县| 鲁甸县| 正阳县| 锡林浩特市| 扎赉特旗| 西畴县| 双柏县| 长宁县| 天津市|