使用ZeroBrane Studio調試Openresty lua腳本


介紹

ZeroBraneStudio 作為輕量級、跨平台的Lua IDE,已被廣泛用來調試各種Lua引擎游戲框架、Openresty、Wireshark腳本等等。

Openresty 是一個建立在Nginx Web應用服務器,一個非常快的Web服務器,提供非阻塞IO(各種后端redis、memcached、MySQL、HTTP服務器等)和支持Lua作為其腳本語言。


目的

本文旨在幫助初涉Openresty開發的相關開發人員了解如何使用ZeroBraneStudio開發和調試自己的lua腳步

如下按照2個步驟說明:

1、安裝Openresty和ZeroBrane Studio

2、編寫簡單Openresty腳步並進行調試


安裝Openresty和ZeroBrane Studio

1、Openresty安裝

Openresty提供多種安裝方式(http://openresty.org/cn/installation.html),在unix系統上我們可以直接使用官方提供的預編譯包直接安裝,使用windows的同學可以直接下載exe運行(http://openresty.org/cn/download.html)。

2、ZeroBraneStudio安裝

從https://github.com/pkulchenko/ZeroBraneStudio/releases下載發布包並解壓,運行zbstudio.exe or zbstudio.sh打開ZeroBraneStudio,同時點擊Project->Project Directory選擇Openresty目錄。


編寫簡單Openresty腳步並進行調試

我們首先更改openresty配置如下:

worker_processes  auto;

worker_rlimit_nofile 65535;

events {
    worker_connections 20480;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    limit_req_zone $binary_remote_addr zone=one:50m rate=20r/s;

    lua_package_path 'D:\ZeroBraneStudio-1.70/lualibs/?/?.lua;D:\ZeroBraneStudio-1.70/lualibs/?.lua;;';
    lua_package_cpath 'D:\ZeroBraneStudio-1.70/bin/clibs/?.dll;;';
    
    include server.conf;
}
    server {
        listen 80;


        location /helloworld {
            default_type text/plain;
            content_by_lua_file D:\openresty-1.13.6.1-win32\lua\content.lua;
        }
    }

然后運行nginx.exe啟動Openresty,點擊Project | Start Debugger Server啟動Debugger Server,在瀏覽器輸入http://localhost/helloworld,然后即可進入斷點調試

(If you are running on OSX, replace ?.dll with ?.dylib and if you are running on Linux, replace bin/clibs/?.dll with either bin/linux/x86/clibs/?.so or bin/linux/x64/clibs/?.so depending on your platform.)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM