Lua 语法学习记录一
来源:互联网 发布:新加坡电信网络制式 编辑:程序博客网 时间:2024/06/05 14:38
local n = 4 function fact( n ) -- 求n的阶乘,递归 if n == 0 then return 1 else return n*fact(n-1) end end print(fact(n)) -- 24 print(type("hello world")) -- string print(type(nil)) -- nil print(type(print)) -- function print(type(true)) -- boolean print(type(type)) -- function print(type(10)) -- number print(type(11.11)) -- number -- 函数赋值 local func = fact print(func(10)) -- 24 -- 字符串 local str = "one string" local str2 = string.gsub(str, "one", "another") print(str2) -- another string print('\97') -- a (ASCII系统) print("10"+1) -- 11 print("10 + 1") -- 10 + 1 -- print("hello" + 1) 错误 print(10 .. 10) -- 1010 ps: ..必须用空格分隔 -- 函数tonumber转换,同理有tostring local str3 = "100" print(100 == "100") -- false print(100 == tonumber(str3)) -- true local str4 = "abcd" print(#str4) -- 4 ps:用#来获取长度 local x = math.pi print(x) -- 3.1415926535898 print(x - x%0.01) -- 3.14 -- == -- 不同类型,肯定是 false -- 同类型,table,userdata,函数 是作引用比较, 其他的是值比较 -- and or print(4 and 5) -- 5 print(nil and 5) -- nil print(4 or 5) -- 4 print(nil or 5) -- 5 print(4 or nil) -- 4 -- 三目运算 c语言中 int value = 5>4?5:4 local value = (5<4) and 5 or 4 -- ((5<4) and 5) or 4 print("value = ", value) -- 4
0 0
- Lua 语法学习记录一
- Lua语法学习(一)
- Lua语法学习(一)
- Lua语法学习笔记(一)
- LUA基本语法一
- Lua语法学习
- Lua语法学习
- lua语法学习
- lua语法学习1
- lua语法学习2
- Lua语法学习笔记
- Lua 基本语法学习
- Lua学习-语法表示
- lua脚本语言学习笔记(一)---LUA变量和循环语法学习
- Lua学习记录
- 学习LUA--零星记录
- lua学习--记录
- lua学习记录
- Android AIDL使用方法详解
- the schema version of 'microsoft.aspnet.mvc' is incompatible with version of nuget
- android系统数据库
- uploadify 3.2.1+spring mvc上传文件
- Opencl 第一节
- Lua 语法学习记录一
- 继承与派生
- android使用ksoap2-android调用webservice时报java.io.EOFException错误
- HDU3882
- ORACLE归档模式
- iOS uitextfield详细使用说明
- Hadoop-2.4.1学习之如何确定Mapper数量
- VB.NET 章鱼哥出品--利用API函数AnimateWindow创建Popup提示窗口,窗体的动画效果
- bmp_to_raw转BMP图片