最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2014年11月03日 16:04:34   投稿:hebedich  
筆者比較熟悉php,所以一直在做一些使用lua來(lái)實(shí)現(xiàn)php中函數(shù)的功能,算是自己對(duì)lua理解的一個(gè)小測(cè)試吧

之前寫(xiě)了一些類似php的函數(shù),下面再來(lái)一個(gè)print_r()函數(shù),代碼如下:

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

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) 

相關(guān)文章

  • Lua中rawset和rawget的作用淺析

    Lua中rawset和rawget的作用淺析

    這篇文章主要介紹了Lua中rawset和rawget的作用淺析,本文分別用兩段代碼演示了rawset和rawget的作用,需要的朋友可以參考下
    2015-04-04
  • Lua中table的遍歷詳解

    Lua中table的遍歷詳解

    這篇文章主要介紹了Lua中table的遍歷詳解,本文講解了4種遍歷方法,并詳細(xì)分析了這4種方法的特點(diǎn)、使用環(huán)境、相關(guān)知識(shí)等,需要的朋友可以參考下
    2015-04-04
  • C語(yǔ)言中調(diào)用Lua函數(shù)實(shí)例

    C語(yǔ)言中調(diào)用Lua函數(shù)實(shí)例

    這篇文章主要介紹了C語(yǔ)言中調(diào)用Lua函數(shù)實(shí)例,本文講解了調(diào)用一個(gè)Lua函數(shù)的步驟和C語(yǔ)言調(diào)用Lua函數(shù)實(shí)例,需要的朋友可以參考下
    2015-04-04
  • Lua中數(shù)字for循環(huán)實(shí)例

    Lua中數(shù)字for循環(huán)實(shí)例

    這篇文章主要介紹了Lua中數(shù)字for循環(huán)實(shí)例,本文直接給出數(shù)字循環(huán)代碼示例,并探討了改變控制變量的一些問(wèn)題,需要的朋友可以參考下
    2015-04-04
  • 深入探究Lua中的解析表達(dá)式

    深入探究Lua中的解析表達(dá)式

    這篇文章主要介紹了深入探究Lua中的解析表達(dá)式,對(duì)于其語(yǔ)法部分的說(shuō)明和示例都超詳細(xì),極力推薦此文!需要的朋友可以參考下
    2015-07-07
  • Lua模塊和模塊載入淺析

    Lua模塊和模塊載入淺析

    這篇文章主要介紹了Lua模塊和模塊載入淺析,Lua模塊其實(shí)就是以.lua結(jié)尾的文件,模塊載入可以用requeire或者dofile,需要的朋友可以參考下
    2014-09-09
  • Lua中的函數(shù)寫(xiě)法簡(jiǎn)明示例

    Lua中的函數(shù)寫(xiě)法簡(jiǎn)明示例

    這篇文章主要介紹了Lua中的函數(shù)寫(xiě)法簡(jiǎn)明示例,本文是一篇個(gè)人學(xué)習(xí)筆記,簡(jiǎn)單的記錄了Lua函數(shù)的寫(xiě)法,需要的朋友可以參考下
    2015-04-04
  • Lua基礎(chǔ)迭代器的使用實(shí)例

    Lua基礎(chǔ)迭代器的使用實(shí)例

    今天小編就為大家分享一篇關(guān)于Lua基礎(chǔ)迭代器的使用實(shí)例,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧
    2018-12-12
  • lua腳本語(yǔ)言快速入門教程

    lua腳本語(yǔ)言快速入門教程

    這篇文章主要介紹了lua腳本語(yǔ)言快速入門教程,本文講解了變量及常量、字符串、邏輯控制語(yǔ)句、循環(huán)結(jié)構(gòu)、函數(shù)及其使用等內(nèi)容,需要的朋友可以參考下
    2015-03-03
  • lua操作excel方法分享

    lua操作excel方法分享

    這篇文章主要介紹了lua操作excel方法分享,在網(wǎng)上幾乎沒(méi)有找到像樣的示例資料,所以自己寫(xiě)了份,推薦給大家。
    2015-03-03

最新評(píng)論

莒南县| 根河市| 静乐县| 平邑县| 南通市| 抚宁县| 东明县| 醴陵市| 汽车| 西丰县| 常德市| 磐安县| 阳西县| 庆安县| 浦县| 吴桥县| 崇仁县| 正宁县| 武乡县| 紫阳县| 湖南省| 全椒县| 姜堰市| 舟山市| 姜堰市| 宁河县| 肇州县| 瑞丽市| 江华| 正镶白旗| 新昌县| 定安县| 梧州市| 茂名市| 蕲春县| 华宁县| 漯河市| 崇左市| 根河市| 东台市| 米易县|