Lua脚本语言基本语法快速入门教程
2015-07-09 09:40
1336 查看
Lua语法与C语言有些相似也不太一样,写了语句学一下 微笑
--begin a = --[[explain]] "ha"; print(a) if a == "ha" then print("if test passed") else print("if used wrong") end b,c=2,3 print(b,c) b,c=c,b if b==3 and c==2 then print("swap test passed") print(b,c) else print("swap error") end do b = 6 if b==6 then print("code block test passed") else print("code block test error") end end do d=true; local e="haha" end if d==true and e==nil then print("local test passed") else print("local test error") end c = 2^3 if c == 8 then print("squert test passed") else print("test error") end a = "string will be ".."connected" print(a) x = x or a --if not x then x = v end print(x) print(type(asdf)) c=3-1.2; print(c) d = [[ 怎么会 怎么会 你竟原谅了我? ]] print(d) function test (w) print("the num is "..w) local add=w+1 return add; end b=test(5) print(add,b) t={ 100, [100] = "I'm the 100th element", fsy= { ['age']=22, sex = "male", --如果是字符串,可以去掉引号和括号 },--元素之间必须用,隔开 20, -- 相当于t[2]=20 } print(t[0]) print(t[1]) print(t[100]) print(t.fsy.age) print(t[2]) g = { age = 3, add=function (s,n) s.age=s.age+n end } g:add(10) --相当于g.add(g,10) print(g.age)
运行的结果如下:
>lua -e "io.stdout:setvbuf 'no'" "hello.lua" ha if test passed 2 3 swap test passed 3 2 code block test passed local test passed squert test passed string will be connected string will be connected nil 1.8 怎么会 怎么会 你竟原谅了我? the num is 5 nil 6 nil 100 I'm the 100th element 22 20 13 >Exit code: 0
您可能感兴趣的文章:
相关文章推荐
- 详解Lua中的表的概念及其相关操作方法
- 把Lua编译进nginx步骤方法
- Lua脚本自动生成APK包
- Lua中的元表(metatable)、元方法(metamethod)详解
- Lua中的metatable介绍
- Lua中ipair和pair的区别
- Lua中的函数精讲笔记
- 浅谈Lua的面向对象特性
- 详解Lua中的变量相关知识点
- Lua脚本语言入门笔记
- Lua脚本调用外部脚本
- 详解Lua中的if语句的使用方法
- Lua中调用函数使用点号和冒号的区别
- Lua中的闭合函数、非全局函数与函数的尾调用详解
- Lua中强大的元方法__index详解
- Lua面向对象之类和继承浅析
- Lua性能优化技巧(一):前言
- Lua中获取table长度问题探讨
- Lua在windows下的安装及环境配置
- Python基本语法与数字类型