国产探花免费观看_亚洲丰满少妇自慰呻吟_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) 
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 区。| 磐安县| 荔波县| 黄大仙区| 宁都县| 岳普湖县| 莱芜市| 威海市| 体育| 泰州市| 蒲城县| 上饶县| 米脂县| 建瓯市| 盈江县| 康定县| 贡觉县| 偃师市| 大丰市| 沽源县| 五家渠市| 凤凰县| 无极县| 阳山县| 普兰店市| 临湘市| 手机| 东安县| 洛南县| 车致| 喀什市| 玉树县| 北宁市| 逊克县| 花莲县| 忻城县| 离岛区| 上虞市| 万年县| 瑞安市| 大方县|