本文使用Windows 11进行编译和安装,其他Windows版本大同小异。

首先到官网下载最新的Lua源码:http://www.lua.org/download.html

另外,需要提前下载并安装 MinGW-w64,具体方式自行解决,本文略

将其解压到任意一个目录,注意该目录路径不要有空格

例如:D:\lua_build\lua-5.4.3

在该目录新建 build.bat,修改以下内容并保存:

set lua_version=5.4.3修改为你下载的Lua版本

set compiler_bin_dir=C:\MinGW-w64\mingw64\bin修改为你的 mingwbin目录

@echo off
:: ========================
:: file build.cmd
:: ========================
setlocal
:: you may change the following variable's value
:: to suit the downloaded version
set lua_version=5.4.3
 
set work_dir=%~dp0
:: Removes trailing backslash
:: to enhance readability in the following steps
set work_dir=%work_dir:~0,-1%
set lua_install_dir=%work_dir%\lua
set compiler_bin_dir=C:\MinGW-w64\mingw64\bin
set lua_build_dir=%work_dir%\lua-%lua_version%
 
cd /D %lua_build_dir%
 
mingw32-make PLAT=mingw
 
echo.
echo **** COMPILATION TERMINATED ****
echo.
echo **** BUILDING BINARY DISTRIBUTION ****
echo.
 
:: create a clean "binary" installation
mkdir %lua_install_dir%
mkdir %lua_install_dir%\doc
mkdir %lua_install_dir%\bin
mkdir %lua_install_dir%\include
 
copy %lua_build_dir%\doc\*.* %lua_install_dir%\doc\*.*
copy %lua_build_dir%\src\*.exe %lua_install_dir%\bin\*.*
copy %lua_build_dir%\src\*.dll %lua_install_dir%\bin\*.*
copy %lua_build_dir%\src\luaconf.h %lua_install_dir%\include\*.*
copy %lua_build_dir%\src\lua.h %lua_install_dir%\include\*.*
copy %lua_build_dir%\src\lualib.h %lua_install_dir%\include\*.*
copy %lua_build_dir%\src\lauxlib.h %lua_install_dir%\include\*.*
copy %lua_build_dir%\src\lua.hpp %lua_install_dir%\include\*.*
 
echo.
echo **** BINARY DISTRIBUTION BUILT ****
echo.
 
%lua_install_dir%\bin\lua.exe -e"print [[Hello!]];print[[Simple Lua test successful!!!]]"
 
echo.
 
pause

右键以管理员身份运行 build.bat

不出意外的话会有如下显示,同时当前目录下出现 lua目录

lua目录放到安装位置,并将其 bin目录添加到环境变量 PATH

输入 lua -i验证安装

完成

最后修改:2021 年 12 月 30 日
如果觉得我的文章对你有用,请随意赞赏