OpenResty 整合 LuaRocks - Windows10

OpenResty Lua LuaRocks About 4,793 words

说明

Windows10下载依赖lua第三方包,通过luarocks包管理。可使用MSVS编译器,但是VS太大,又不太常用,可使用MinGW来代替。

安装MinGW

下载地址:https://sourceforge.net/projects/mingw/files/latest/download?source=files

  1. 双击mingw-get-setup.exe,安装即可;
  2. 在主界面左侧菜单栏选择Basic Setup
  3. 在右侧菜单栏中选择mingw32-base,右击,选择Make for Installation
  4. 选择左上角Installation选项卡,点击Apply Changes
  5. 将安装路径bin目录(如:C:\MinGW\bin)添加到PATH环境变量中;

特别注意:
安装过程可能会出现依赖包下载不成功,此时,需查看Installation选项卡中的Apply Changes是否变为灰色(即:不可点击),变为灰色则说明安装成功了,否则再次点击Apply Changes

安装luarocks

下载地址:https://luarocks.github.io/luarocks/releases

cmd中执行(必须以管理员身份执行,否则安装会失败),其中PREFIXOpenResty文件夹路径,安装成功也需要将D:\lua\openresty-1.15.8.2-win32\luarocks添加到系统环境变量中。

set PREFIX=D:\lua\openresty-1.15.8.2-win32
install /P %PREFIX%\luarocks /SELFCONTAINED /INC %PREFIX%\include\luajit-2.1 /LIB %PREFIX% /BIN %PREFIX% /MW
  • /P:表示把luarocks安装在OpenRestyluarocks文件夹;
  • /SELFCONTAINED:表示/TREE/CONFIG选项的值和/P一致。这样就所有第三方包都在luarocks这个文件里,方便查找;
  • /INC:表示luajit的include库所在的文件夹;
  • /LIB:表示lua51.dll所在的文件夹;
  • /BIN:表示luajit.exe所在的文件夹;
  • /MW:表示用mingw32-gcc.exe编译器;

成功提示

D:\lua\luarocks-3.3.1-win32>rem=rem --[[--lua
LuaRocks 3.3.x installer.


========================
== Checking system... ==
========================


Admin privileges available for installing
Looking for Lua interpreter
       Found luajit.exe, testing it...
    checking for D:\lua\openresty-1.15.8.2-win32\lua5.1.lib
    checking for D:\lua\openresty-1.15.8.2-win32\lua51.lib
    checking for D:\lua\openresty-1.15.8.2-win32\lua5.1.dll
    checking for D:\lua\openresty-1.15.8.2-win32\lua51.dll
       Found lua51.dll
    checking for D:\lua\openresty-1.15.8.2-win32\include\luajit-2.1\lua.h
       Found lua.h
    D:\lua\openresty-1.15.8.2-win32\luajit.exe uses MSVCRT.DLL as runtime
Runtime check completed.
arch: 14c -> IMAGE_FILE_MACHINE_I386

==========================
== System check results ==
==========================

Will configure LuaRocks with the following paths:
LuaRocks        : D:\lua\openresty-1.15.8.2-win32\luarocks
Config file     : D:\lua\openresty-1.15.8.2-win32\luarocks\config-5.1.lua
Rocktree        : D:\lua\openresty-1.15.8.2-win32\luarocks\systree

Lua interpreter : D:\lua\openresty-1.15.8.2-win32\luajit.exe
    binaries    : D:\lua\openresty-1.15.8.2-win32
    libraries   : D:\lua\openresty-1.15.8.2-win32
    includes    : D:\lua\openresty-1.15.8.2-win32\include\luajit-2.1
    architecture: x86
    binary link : lua51.dll with runtime MSVCRT.dll

Compiler        : MinGW/gcc (make sure it is in your path before using LuaRocks)
                  in: C:\MinGW\bin

Press <ENTER> to start installing, or press <CTRL>+<C> to abort. Use install /? for installation options.


============================
== Installing LuaRocks... ==
============================


Installing LuaRocks in D:\lua\openresty-1.15.8.2-win32\luarocks...
Created LuaRocks command: D:\lua\openresty-1.15.8.2-win32\luarocks\luarocks.bat
Created LuaRocks command: D:\lua\openresty-1.15.8.2-win32\luarocks\luarocks-admin.bat

Configuring LuaRocks...
Created LuaRocks hardcoded settings file: D:\lua\openresty-1.15.8.2-win32\luarocks\lua\luarocks\core\hardcoded.lua
Created LuaRocks config file: D:\lua\openresty-1.15.8.2-win32\luarocks\config-5.1.lua

Creating rocktrees...
Created system rocktree    : "D:\lua\openresty-1.15.8.2-win32\luarocks\systree"
Local user rocktree exists : "C:\Users\fendoudebb\AppData\Roaming\LuaRocks"

============================
== LuaRocks is installed! ==
============================


You may want to add the following elements to your paths;
Lua interpreter;
  PATH     :   D:\lua\openresty-1.15.8.2-win32
  PATHEXT  :   .LUA
LuaRocks;
  PATH     :   D:\lua\openresty-1.15.8.2-win32\luarocks
  LUA_PATH :   D:\lua\openresty-1.15.8.2-win32\luarocks\lua\?.lua;D:\lua\openresty-1.15.8.2-win32\luarocks\lua\?\init.lua
Local user rocktree (Note: %APPDATA% is user dependent);
  PATH     :   %APPDATA%\LuaRocks\bin
  LUA_PATH :   %APPDATA%\LuaRocks\share\lua\5.1\?.lua;%APPDATA%\LuaRocks\share\lua\5.1\?\init.lua
  LUA_CPATH:   %APPDATA%\LuaRocks\lib\lua\5.1\?.dll
System rocktree
  PATH     :   D:\lua\openresty-1.15.8.2-win32\luarocks\systree\bin
  LUA_PATH :   D:\lua\openresty-1.15.8.2-win32\luarocks\systree\share\lua\5.1\?.lua;D:\lua\openresty-1.15.8.2-win32\luarocks\systree\share\lua\5.1\?\init.lua
  LUA_CPATH:   D:\lua\openresty-1.15.8.2-win32\luarocks\systree\lib\lua\5.1\?.dll

Note that the %APPDATA% element in the paths above is user specific and it MUST be replaced by its actual value.
For the current user that value is: C:\Users\fendoudebb\AppData\Roaming.

OpenResty配置

demo/?.lua;;是工程的目录文件夹,删除也可。

http {
    lua_package_path "demo/?.lua;;luarocks\systree\share\lua\5.1\?.lua;luarocks\systree\share\lua\5.1\?\init.lua;;";
    lua_package_cpath "luarocks\systree\lib\lua\5.1\?.dll;;";
}

参考

luarocks-Windows平台安装

Views: 4,125 · Posted: 2020-02-19

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh