摘要: 一)全局-局部变量 全局变量是指:这个变量在没有被同名局部变量覆盖的时候,所有代码块都是可见的。 局部变量是指:该变量只在被申明的代码块中可见,并且可以覆盖同名全局变量或者外层局部变量。 Lua 中的局部变量要用 local 关键字来显式定义,不使用 local 显式定义的变量就是全局变量: g_v 阅读全文
posted @ 2021-06-26 20:37 hochan_100 阅读(184) 评论(0) 推荐(0) 编辑
摘要: Lua中table内部实际采用哈希表和数组分别保存键值对、普通值;下标从1开始 不推荐混合使用这两种赋值方式。 local color={first="red", "blue", third="green", "yellow"} print(color["first"]) --> output: r 阅读全文
posted @ 2021-06-26 14:34 hochan_100 阅读(5541) 评论(0) 推荐(0) 编辑
摘要: string的相关操作 1)string.upper(s) 接收一个字符串 s,返回一个把所有小写字母变成大写字母的字符串。 print(string.upper("Hello Lua")) -->output HELLO LUA 2)string.lower(s) 接收一个字符串 s,返回一个把所 阅读全文
posted @ 2021-06-26 14:13 hochan_100 阅读(714) 评论(0) 推荐(0) 编辑
摘要: 之前我们介绍了 条件判断的 if 用于循环迭代的 while、repeat 四)for 控制结构 for 语句有两种形式:数字 for 和范型 for。 1)数字型 for 的语法如下: for var = begin, finish, step do --body end 关于数字 for 需要关 阅读全文
posted @ 2021-06-26 14:07 hochan_100 阅读(89) 评论(0) 推荐(0) 编辑
摘要: 一)条件 - 控制结构 if-else if-else 是我们熟知的一种控制结构。Lua 跟其他语言一样,提供了 if-else 的控制结构。 1)单个 if 分支 型 if 条件 then --body end 条件为真 ,执行if中的body x = 10 if x > 0 then print 阅读全文
posted @ 2021-06-26 11:17 hochan_100 阅读(202) 评论(0) 推荐(0) 编辑
摘要: 一)算术运算符 + 加法 - 减法 * 乘法 / 除法 % 取余 ^ 乘幂 - 负号 print(1 + 2) -->打印 3 print(5 / 10) -->打印 0.5。 这是Lua不同于c语言的 print(5.0 / 10) -->打印 0.5。 浮点数相除的结果是浮点数 -- print 阅读全文
posted @ 2021-06-26 11:14 hochan_100 阅读(372) 评论(0) 推荐(0) 编辑
摘要: 一)table (表) Table 类型实现了一种抽象的“关联数组”。即可用作数组,也可以用作map。 lua中没有数组和map,都是用table这个类型 --数组 java int[] intArr = new int[]{1,2,3,4,5,6}; intArr[0] intArr[1] --m 阅读全文
posted @ 2021-06-26 11:05 hochan_100 阅读(321) 评论(0) 推荐(0) 编辑
摘要: 一)function (函数) 有名函数: optional_function_scope function function_name( argument1, argument2, argument3..., argumentn) function_body return result_param 阅读全文
posted @ 2021-06-26 10:58 hochan_100 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 1)ngx_lua模块的hello world 编辑nginx下conf配置文件nginx.conf # vi nginx.conf 在server模块加上 location /helloworld { default_type text/html; content_by_lua 'ngx.say( 阅读全文
posted @ 2021-06-26 08:26 hochan_100 阅读(116) 评论(0) 推荐(0) 编辑
摘要: 1)下载安装 centos系统 yum install readline-devel pcre pcre-devel openssl openssl-devel gcc curl GeoIP-devel 下载源码包 https://github.com/openresty/openresty/rel 阅读全文
posted @ 2021-06-26 08:07 hochan_100 阅读(68) 评论(0) 推荐(0) 编辑