Lua
ivalue2333
He wept, for there were no more worlds to conquer.
展开
-
lua-table使用笔记
参考:https://www.cnblogs.com/Dong-Forward/p/6063365.html1:lua的table你可以先理解为既是一个数组也是一个字典2:table判空function isTableEmpty (t) if t == nil or next (t) == nil then return true else ...原创 2018-09-12 21:30:33 · 199 阅读 · 0 评论 -
lua--switch的语法实现
function test1() print("test1") print(test1)endfunction test2(val) print(val)endlocal switch = { test1 = test1, t2 = test2,}local t1 = switch["test1"]t1()print(t1)print("------")...原创 2018-09-17 09:24:13 · 7308 阅读 · 0 评论 -
lua-深复制table
--categroty 工具方法--src 源字符串--dest 目标字符串function _M.table_copy(src, dest) for k, v in pairs(src) do if type(v) == "table" then dest[k] = {} _M.table_copy(v,...原创 2018-09-17 11:55:19 · 978 阅读 · 0 评论 -
Lua-Json解析的性能问题
1:环境基于openresty建站openresty版本1.11.2.5LuaJIT 版本2.1.0Luarocks版本2.4.4通过Luarocks安装cjson()openresty官网说自带cjson模块,这个没有测试,反正我这里是通过Luarocks安装cjson。2:解析Json采用ngx.say输出json,在body_filter_by_lua_file中...原创 2018-09-06 10:23:44 · 2556 阅读 · 0 评论 -
lua-点号,冒号,self
1:self类似c++中的this指针,指向当前正在使用这个table的实例2:”.”点号就是基本的table索引的方式3:”:”冒号,记住一点就是省略self这个参数的作用,无论是在定义函数,还是在调用函数都是这个作用。冒号只能用于函数调用和定义,不能用于其他的情况local mt = {}mt.num = 100function mt.add_num(n) mt....原创 2018-09-13 10:05:14 · 176 阅读 · 0 评论 -
lua-ipairs, pairs遍历table
1:ua 5.3 手册http://www.lua.org/manual/5.3/manual.html2:ipairs (t)Returns three values: an iterator function, the table t, and 0, so that the constructionfor i,v in ipairs(t) do body endwill...原创 2018-09-13 10:50:17 · 702 阅读 · 0 评论 -
lua-引用传递和值传递
function test1(tt) tt = {1, 3, 5}endfunction test2(tt) tt[1] = 2 tt["a"] = "hello"endt = {4, 5, 6}test1(t)for k,v in pairs(t) do print(v)endprint("------")t = {4, 5, 6...原创 2018-09-27 14:01:06 · 6128 阅读 · 0 评论