<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>lua - 标签 - cfanzp学习笔记</title>
    <link>https://cfanzp008.github.io/tags/lua/</link>
    <description>lua - 标签 - cfanzp学习笔记</description>
    <generator>Hugo -- gohugo.io</generator><language>zh-CN</language><managingEditor>cfan.zp@qq.com (cfanzp)</managingEditor>
      <webMaster>cfan.zp@qq.com (cfanzp)</webMaster><lastBuildDate>Sat, 01 Apr 2023 16:41:57 &#43;0800</lastBuildDate><atom:link href="https://cfanzp008.github.io/tags/lua/" rel="self" type="application/rss+xml" /><item>
  <title>lua常见问题</title>
  <link>https://cfanzp008.github.io/lua-question/</link>
  <pubDate>Sat, 01 Apr 2023 16:41:57 &#43;0800</pubDate>
  <author>作者</author>
  <guid>https://cfanzp008.github.io/lua-question/</guid>
  <description><![CDATA[]]></description>
</item>
<item>
  <title>lua中给日志关键字加上颜色</title>
  <link>https://cfanzp008.github.io/terminal-color/</link>
  <pubDate>Tue, 06 Sep 2022 17:05:35 &#43;0800</pubDate>
  <author>作者</author>
  <guid>https://cfanzp008.github.io/terminal-color/</guid>
  <description><![CDATA[]]></description>
</item>
<item>
  <title>lua-pbc(lua的protobuf库)如何使用？</title>
  <link>https://cfanzp008.github.io/lua-pbc/</link>
  <pubDate>Tue, 30 Aug 2022 08:36:15 &#43;0800</pubDate>
  <author>作者</author>
  <guid>https://cfanzp008.github.io/lua-pbc/</guid>
  <description><![CDATA[lua-pbc(lua的protobuf库)如何使用？ lua-pbc是什么? lua-pbc,即lua protocol buffer fro c,是云风写的一个给lua使用的protobuf封包解包的库,如果你想用skynet来写游戏等服务端应用，lua-pbc是不错的选择。
lua-pbc github地址为: https://github.com/cloudwu/pbc
关于pbc的设计，大家可以看一下云风的博客: https://blog.codingnow.com/2011/12/protocol_buffers_for_c.html
lua-pbc如何使用？ 这里有几个接个api需要熟悉一下
编写protobuf的proto文件 User.proto
1 2 3 4 package tutorial; message User { optional string name = 1; } 引入模块protobuf
1 local pb = require &#34;protobuf&#34; 注册文件
1 pb.register_file &#34;User.pb&#34; encode
1 2 3 4 local msg_table = { name = &#34;test1&#34; } pb.encode(&#34;tutorial.User&#34;,msg_table}, decode
1 local msg_table = pb.decode(&#34;tutorial.Person&#34;, buf) 使用感受 lua-pbc使用了很长一段时间，官方skynte升级支持lua5.4以后，pbc还是可以正常工作的。 pbc的接口设计是比较简洁的，用起来也非常方便。想深入了解的同学，建议去看看源码。
参考 pbc: https://github.com/cloudwu/pbc pbc binding lua: https://github.]]></description>
</item>
<item>
  <title>lua中如何实现打印行号和当前函数名？</title>
  <link>https://cfanzp008.github.io/lua-debug/</link>
  <pubDate>Tue, 23 Aug 2022 11:28:13 &#43;0800</pubDate>
  <author>作者</author>
  <guid>https://cfanzp008.github.io/lua-debug/</guid>
  <description><![CDATA[lua中如何实现打印行号和当前函数名？ lua中可以使用debug的get_info方法来获取当前的堆栈信息，进而可以打印出相关的环境信息，具体信息包括:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 table: 0x7f92b8f19e80 { isvararg = false , what = Lua , func = function: 0x7f92b7b8d600 , namewhat = , istailcall = true , lastlinedefined = 16 , source = @service/db/db_interactionemotion.lua , linedefined = 7 , currentline = 11 , ntransfer = 0 , short_src = service/db/db_interactionemotion.lua , ftransfer = 0 , nups = 3 , nparams = 0 , } lua中需要打印行号多半是日志需求，下面是一个demo:]]></description>
</item>
<item>
  <title>lua中的self</title>
  <link>https://cfanzp008.github.io/lua-self/</link>
  <pubDate>Tue, 09 Aug 2022 22:40:06 &#43;0800</pubDate>
  <author>作者</author>
  <guid>https://cfanzp008.github.io/lua-self/</guid>
  <description><![CDATA[lua中的self self的用法 使用:定义的函数默认接收第一个参数是self 使用:调用函数默认传入第一个参数是调用者 使用.定义和调用函数不会接受或传入self :为我们省下了一个参数，下面例子中的A:Add()与A.Add(t)是等价的
1 2 3 4 5 6 7 local A = {x = 1, y = 2} function t:Add() return (self.x + self.y) end print(A:Add()) print(A.Add(A)) ]]></description>
</item>
<item>
  <title>lua面向对象编程</title>
  <link>https://cfanzp008.github.io/lua-new/</link>
  <pubDate>Mon, 08 Aug 2022 09:18:02 &#43;0800</pubDate>
  <author>作者</author>
  <guid>https://cfanzp008.github.io/lua-new/</guid>
  <description><![CDATA[lua面向对象编程 对象定义: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 local logger = require &#34;common.]]></description>
</item>
<item>
  <title>lua第三方开源库学习整理</title>
  <link>https://cfanzp008.github.io/lua-3rd/</link>
  <pubDate>Wed, 03 Aug 2022 09:01:02 &#43;0800</pubDate>
  <author>cfanzp</author>
  <guid>https://cfanzp008.github.io/lua-3rd/</guid>
  <description><![CDATA[lua第三方开源库学习整理 skynet框架:https://github.com/cloudwu/skynet lua的protobuf工具-pbc:https://github.com/cloudwu/pbc lua-cjson库:https://github.com/mpx/lua-cjson 一个lua写的websocket库https://github.com/flaribbit/love2d-lua-websocket lua-protobuf库https://github.com/starwing/lua-protobuf/blob/master/README.zh.md ]]></description>
</item>
<item>
  <title>lua中string.pack,string.unpack的用法</title>
  <link>https://cfanzp008.github.io/lua-string-pack/</link>
  <pubDate>Wed, 03 Aug 2022 08:34:18 &#43;0800</pubDate>
  <author>cfanzp</author>
  <guid>https://cfanzp008.github.io/lua-string-pack/</guid>
  <description><![CDATA[lua中string.pack,string.unpack的用法 lua string.pack的用法,查看lua5.4的官方帮助手册不难找到下面的解释:
string.pack (fmt, v1, v2, ···)
Returns a binary string containing the values v1, v2, etc. serialized in binary form (packed) according to the format string fmt (see §6.4.2).
最近一个新项目要将brotobuf协议包裹在http协议内进行传输，刚好用到了这个函数,在pb数据包封包后，协议按3部分拼接:
1 数据包长度(msgid + pb_data) + 协议ID + pb数据包体 封包过程如下:
1 2 3 local pb_data = pb_helper.pb_encode(msgname, msg) local buf = string.pack(&#34;&gt;I4c&#34; .. #pb_data, msgid, pb_data) local send_buf = string.pack(&#34;&gt;s2&#34;, buf) 解包过程如下:
1 2 3 local buf = msg --des_decode(secret, msg) local len = string.]]></description>
</item>
<item>
  <title>Lua开发手册</title>
  <link>https://cfanzp008.github.io/lua-man/</link>
  <pubDate>Sun, 31 Jul 2022 09:47:48 &#43;0800</pubDate>
  <author>cfanzp</author>
  <guid>https://cfanzp008.github.io/lua-man/</guid>
  <description><![CDATA[lua5.3开发手册 https://cloud.tencent.com/developer/doc/1141 云风翻译:http://cloudwu.github.io/lua53doc/manual.html lua5.4开发手册 官网英文版:http://www.lua.org/manual/5.4/manual.html lua匹配库Lpeg 官网: http://www.inf.puc-rio.br/~roberto/lpeg/ 帮助: https://www.jianshu.com/p/e8e1c5abfdbb tutorial: https://lua-users.org/wiki/LpegTutorial luasocket github: https://github.com/lunarmodules/luasocket 使用demo: https://blog.csdn.net/h1023417614/article/details/52297408 lua md5 github: https://github.com/keplerproject/md5 jemalloc http://jemalloc.net/ ]]></description>
</item>
</channel>
</rss>
