ZeroBrane Studio简介和功能
ZeroBrane Studio是一个轻量级的Lua IDE,具有代码完成,语法高亮,实时编码,代码分析器以及Lua 5.1,Lua 5.2,Lua 5.3, LuaJIT和其他Lua引擎的调试支持……具体可访问ZeroBrane Studio官网,本文主要介绍ZeroBrane Studio开发调试OpenResty的环境配置
下载ZeroBrane Studio和OpenResty
openresty下载:openresty-1.13.6.2-win32
ZeroBrane Studio下载:ZeroBraneStudio
将ZeroBrane Studio和openresty解压到指定目录即可(本文解压路径D:\opt)
配置ZeroBrane Studio和OpenResty
编辑D:\opt\openresty-1.13.6.2-win32\conf\nginx.conf,OpenResty引入ZeroBrane Studio模块
1 2 |
lua_package_path 'D:/opt/zbstudio/lualibs/?/?.lua;D:/opt/zbstudio/lualibs/?.lua;;'; lua_package_cpath 'D:/opt/zbstudio/bin/clibs/?.dll;;'; |
创建lua脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
require("mobdebug").start("127.0.0.1") --用于接收前端数据的对象 local args=nil --获取前端的请求方式 并获取传递的参数 local request_method = ngx.var.request_method --判断是get请求还是post请求并分别拿出相应的数据 if"GET" == request_method then args = ngx.req.get_uri_args() elseif "POST" == request_method then ngx.req.read_body() args = ngx.req.get_post_args() --兼容请求使用post请求,但是传参以get方式传造成的无法获取到数据的bug if (args == nil or args.data == null) then args = ngx.req.get_uri_args() end end --获取前端传递的name值 local name = args.name --响应前端 ngx.say("hello:"..name) |
OpenResty引用刚才创建的Lua脚本,填写绝对路径,否则会找不到文件
1 2 3 4 5 |
location /luatest { #lua_code_cache off; default_type text/html; content_by_lua_file d:/opt/openresty-1.13.6.2-win32/lualib/test/testlua.lua; } |
重启OpenResty或nginx.ext -s reload,ZeroBrane Studio开启调试模式
添加监视表达式,实时查看变量的值
浏览器访问http://127.0.0.1/luatest?name=Lua
ZeroBrane Studio会进入绿色箭头对应行的代码
调试快捷键
F10 下一行
Shift+F10 跳过调试
Ctrl +F10 跳过当前function
Shift + F5 终止运行
F6 运行
F5 debug运行
采用最新openresty-1.15.8.3-win32调试会有问题,后台改用openresty-1.13.6.2版本正常,openresty-1.13.6.2下载地址在上方
引用:https://blog.csdn.net/lupengfei1009/article/details/86071905