Lua编程示例(一):select、debug、可变参数、table操作、error
2015-07-09 10:29
1571 查看
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.level<b.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)
运行结果为:
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
相关文章推荐
- 访问Nginx发生SSL connection error的一种情况
- 神器SystemTap
- Python 七步捉虫法
- 星外虚拟主机访问被控出现Unspecified error解决方法
- IIS 错误 Server Application Error 详细解决方法
- On Error Resume Next 语句
- 表格标签table深入了解
- Jquery实现的table最后一行添加样式的代码
- 详解Lua中的表的概念及其相关操作方法
- IIS运行错误 Server Application Error 错误代码 Error: 8004的解决方法
- 把Lua编译进nginx步骤方法
- Lua脚本自动生成APK包
- Lua中的元表(metatable)、元方法(metamethod)详解
- Lua中的metatable介绍
- Lua中ipair和pair的区别
- Lua中的函数精讲笔记
- 浅谈Lua的面向对象特性
- 详解Lua中的变量相关知识点
- Lua脚本语言入门笔记
- Lua脚本调用外部脚本