lua基础语法
2016-03-24 18:05
1236 查看
简单的语法,自己留个学习笔记而已
运行结果如下:
if(0) then print("0 is true") end a = 1 if(a) then print("1 is false") else print("a is true") end a = 100 if(a == 50) then print("the value of a is 50") elseif(a == 100) then print("the value of a is 100") else print("the value of a is not matched") end -- test loop of 'for' days = {'sunday','monday','tuesday','wednesday','thursday','friday','saturday'} for i,v in ipairs(days) do print(i,v) end -- test loop of 'repeat' a = 10 repeat print('the value of a is ',a) a = a + 1 until(a > 15) -- test for function in lua myprint = function(param) print("this is print fun ###",param,"###") end function add (num1,num2,functionprint) result = num1 + num2 -- call function from passed functionprint(result) end myprint(100) add(10,20,myprint) -- test for the number of args is not sure function average(...) result = 0 local arg = {...} for i,v in ipairs(arg) do result = result + v end print('the number of arg is'..#arg..'size') return result/#arg end print("the average is ",average(10,5,6,20,2))
运行结果如下:
相关文章推荐
- C++调用Lua函数
- C++将结构体传给lua
- Lua和C++语言的交互详解
- LUA 怎么理解coroutine ?
- lua脚本入门
- lua入门之二:c/c++ 调用lua及多个函数返回值的获取
- Lua和C++交互详细总结
- Lua_第18 章 Table 库
- Lua_第17 章 数学库
- lua安装和简单测试
- Lua垃圾回收
- lua绑定
- Lua简明教程
- lua常用函数
- Dorothy Lua开发建议
- 基于 lua 的热更新系统设计要点
- 167.Evaluate the following DELETE statement:
- 战火引擎中如何写Lua逻辑脚本
- Lua 中使用面向对象(续)--newproxy生成userdata使用__gc
- lua gc 优化方案