lua基础语法
2016-06-25 10:52
411 查看
if(0) 02.then 03. print("0 is true") 04.end 05. 06.a = 1 07. 08.if(a) 09.then 10. print("1 is false") 11.else 12. print("a is true") 13.end 14. 15.a = 100 16.if(a == 50) 17.then 18. print("the value of a is 50") 19.elseif(a == 100) 20.then 21. print("the value of a is 100") 22.else 23. print("the value of a is not matched") 24.end 25. 26.-- test loop of 'for' 27. 28.days = {'sunday','monday','tuesday','wednesday','thursday','friday','saturday'} 29.for i,v in ipairs(days) do print(i,v) end 30. 31.-- test loop of 'repeat' 32.a = 10 33.repeat 34. print('the value of a is ',a) 35. a = a + 1 36.until(a > 15) 37. 38.-- test for function in lua 39.myprint = function(param) 40. print("this is print fun ###",param,"###") 41.end 42. 43.function add (num1,num2,functionprint) 44. result = num1 + num2 45. -- call function from passed 46. functionprint(result) 47.end 48. 49.myprint(100) 50. 51.add(10,20,myprint) 52. 53.-- test for the number of args is not sure 54.function average(...) 55. result = 0 56. local arg = {...} 57. for i,v in ipairs(arg) 58. do 59. result = result + v 60. end 61. print('the number of arg is'..#arg..'size') 62. return result/#arg 63.end 64. 65.print("the average is ",average(10,5,6,20,2)) 运行结果如下: <img alt="" src="http://img.blog.csdn.net/20160324180820443?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" />
相关文章推荐
- 100行lua代码实现简单目录浏览器
- fblualib安装教程
- Lua 函数参数万能转化基本数据类型
- lua 中调用函数的坑点
- LuaJavaBridge - Lua 与 Java 互操作的简单解决方案
- 使用Lua编写Web端模板引擎的实例代码分享
- lua计算时间差 按照日历方式来计算时间差 而不是固定每个月都是多少天来计算
- 编译lua5.3扩展.so文件时遇到的一些问题总结
- Metatable 对象默认的操作方式
- lua 闭包
- Metatable与面向对象、继承
- lua 读取lua文件
- 【转】编译Lua5.3.0的iOS静态库
- 多线程中的lua同步问题
- luarocks学习
- lua package匹配机制
- Lua函数
- xavante运行cgilua流程
- Vim 7.4.1952 with Python/Ruby/Lua/Perl/C Syntax built for Ubuntu 16.04 x86_64
- Lua自己实现angle角