function test_print(...) for i=1,select("#",...) do print(i,select(i,...)) end end test_print(11,12,13,14) print() print(debug.traceback()) print() function test(...) for i=1,arg.n do print(i.."\t"..arg[i]) end end test("a",2,34,234) print() g={} table.insert(g,{ name="Clairs", level = 70, }) table.insert(g,{ name="SEGA", level = 35, }) table.insert(g,{ name="Millber", level = 50, }) function myprint() for i,v in ipairs(g) do print(i,v["level"],v.name) end end myprint() function comp(a,b) return a.levelb.level end table.sort(g,comp) print() myprint() print() function foo(str) if type(str) ~= "string" then error("string error!",2) end end --foo({x =1 }) tb1={ "asdf","bate","game",one="heihei"} table.insert(tb1,3,"haha") table.remove(tb1,2) for i,v in ipairs(tb1) do print(v) end print(#tb1)
運(yùn)行結(jié)果為:
1 11 12 13 14 2 12 13 14 3 13 14 4 14 stack traceback: my_test.lua:12: in main chunk [C]: ? 1 a 2 2 3 34 4 234 1 70 Clairs 2 35 SEGA 3 50 Millber 1 35 SEGA 2 50 Millber 3 70 Clairs asdf haha game 3
標(biāo)簽:昌都 南京 營(yíng)口 宿遷 臨滄 西寧 泰安
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Lua編程示例(一):select、debug、可變參數(shù)、table操作、error》,本文關(guān)鍵詞 Lua,編程,示例,一,select,debug,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。