随笔 - 230  文章 - 0 评论 - 0 阅读 - 88380
< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5

LUA

lua 版本 (5.1+)

当前多数模块对lua的版本都是5.1以上,因此要注意版本。
https://luabinaries.sourceforge.net/download.html

luarocks

Luarocks 是一个用于 Lua 编程语言的包管理器。类似java中的maven,python中的pip。
luarocks 可从网址查看是否具有响应的包,网址:https://luarocks.org/
luarocks的下载包 https://luarocks.github.io/luarocks/releases/
版本对应关系:luarocks 3.1.3 -> lua 5.3+
luarocks 2.2 -> lua 5.1+

luarocks install lpeg 2.5

对于手动下载的模块源码,可以查找对应的 rockspec 文件,执行。
示例:

luarocks make lua-tinyyaml-1.0-0.rockspec

vscode加载lua

1.安装lua debug 插件

应用的vsCode环境中的项目settings.json填写以下内容:

{
    "lua.debug.settings.luaVersion": "lua51",
    "lua.debug.settings.cpath": "D:\\software\\LUA5.1\\lua\\?.dll;${workspaceFolder}/?.dll",
    "lua.debug.settings.path": "D:\\software\\LUA5.1\\lua\\?.lua;${workspaceFolder}/?.lua"
}

常用模块

tinny yaml

因tinnyyaml不依赖其它项也无so文件,如果下载不下来,可以手动从git上下载,将tinny-yaml.lua放入到lua5.1/lua下。

local yaml = require("tinyyaml")
local template = require("resty.template")

local file = io.open("./config/config.yaml", "r")
local content
if file then
    content = file:read("*a")
    file:close()
    -- 此时content变量中存储了YAML文件的全部内容
else
    print("无法打开配置文件")
    return
end
if content then
    local configData = yaml.parse(content)
    print(configData.waf.enabled)
end

resty template

local template = require("resty.template")


local sys_conf = {
    waf = "on"
}

local ngx_tpl = [[
waf = {* waf *};
{{waf}}
]]


local conf_render = template.compile(ngx_tpl)
local ngxconf = conf_render(sys_conf)
print(ngxconf)

inspect

用于快速输出table对象,因table对象无法直接打印,看不到内部的数据

local inspect = require("inspect")
print(inspect(sys_conf))
posted on   zhaoqiang1980  阅读(75)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
点击右上角即可分享
微信分享提示