文章目录

  • # win 运行(直接下载可执行文件)
  • # 集成开发环境
  • # linux 编译
  • # win 编译(非集成环境)
  • # win 编译(visual studio)
  • 安装 visual studio
  • 创建空白解决方案
  • 创建静态库项目
  • 创建控制台项目
  • 调试
  • 添加引用
  • # 编译 lua/luac 源代码


# win 运行(直接下载可执行文件)

http://www.lua.org/download.html

luac反编译后是空的 luac反编译lua_编译


解压到方便的目录

luac反编译后是空的 luac反编译lua_luac反编译后是空的_02

配置环境变量

luac反编译后是空的 luac反编译lua_lua_03


luac反编译后是空的 luac反编译lua_集成环境_04

  • lua54.exe 为lua解释器
  • luac54.exe 为lua编译器
    想直接输入lua,可以把 lua54.exe 重命名 为 lua.exe 就可以了
  • wlua54.exe 类似于lua54.exe但不提供控制台输出
  • lua54.dll 为动态链接库

# 集成开发环境

# linux 编译

源码下载:https://www.lua.org/ftp/lua-5.0.tar.gz

# 下载
# -inet4-only: ipv6 连不上,所以才添加 
$ wget https://www.lua.org/ftp/lua-5.0.tar.gz -inet4-only 

# 解压
$ tar zxvf lua-5.0.tar.gz

# 编译
# $ sudo apt install build-essential
$ cd lua-5.0
$ make linux

# 编译结果在: src/lua、src/luac

# win 编译(非集成环境)

https://medium.com/@CassiusBenard/lua-basics-windows-7-installation-and-running-lua-files-from-the-command-line-e8196e988d71

@echo off
 :: ========================
 :: file build.cmd
 :: ========================
 setlocal
 :: you may change the following variable’s value
 :: to suit the downloaded version
 set lua_version=5.3.2
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=%work_dir%\tdm-gcc\bin
 set lua_build_dir=%work_dir%\lua-%lua_version%
 set path=%compiler_bin_dir%;%path%
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

# win 编译(visual studio)

安装 visual studio

安装 visualstudio:https://visualstudio.microsoft.com/zh-hans/

安装时需要勾选 “使用 C++ 的桌面开发”(需要包含 MSVC、CMake等编译c、c++的东西)

luac反编译后是空的 luac反编译lua_编译_05

luac反编译后是空的 luac反编译lua_开发语言_06

创建空白解决方案

luac反编译后是空的 luac反编译lua_集成环境_07


luac反编译后是空的 luac反编译lua_编译_08

复制 lua src 进入解决方案目录

luac反编译后是空的 luac反编译lua_编译_09

创建静态库项目

luac反编译后是空的 luac反编译lua_开发语言_10


luac反编译后是空的 luac反编译lua_luac反编译后是空的_11

起名 lualib (随意)

luac反编译后是空的 luac反编译lua_luac反编译后是空的_12

在 lualib 项目中添加现有项目,选择 src 中的所有 c 文件(同时,不包括 lua.cluac.c

luac反编译后是空的 luac反编译lua_开发语言_13

修改项目属性,将“预编译头”的值改为“不使用预编译头”

luac反编译后是空的 luac反编译lua_开发语言_14


同时,复制“输出目录”

luac反编译后是空的 luac反编译lua_集成环境_15

这时候点击生成,是可以成功生成的

luac反编译后是空的 luac反编译lua_lua_16


luac反编译后是空的 luac反编译lua_编译_17

创建控制台项目

“新建项目” - “控制台应用”

luac反编译后是空的 luac反编译lua_编译_18


起名 “luacon” (随便)

luac反编译后是空的 luac反编译lua_开发语言_19

添加现有项目,把(刚才排除的) lua.clua.h 添加进来

同样的,检查 “编译头” 属性要设置成 “不使用编译头”

luac反编译后是空的 luac反编译lua_开发语言_20

添加 “附加库目录”:刚才创建的静态库项目 lualib 的输出路径

luac反编译后是空的 luac反编译lua_开发语言_21


最后,在 “插入”-“添加依赖项” 中添加 lualib.lua 即可编译运行了

luac反编译后是空的 luac反编译lua_luac反编译后是空的_22

调试

luacon 中右键,设置成 “起动项目” 即可在上面的目录中间运行 ▶️ 运行调试了。

luac反编译后是空的 luac反编译lua_lua_23

luac反编译后是空的 luac反编译lua_编译_24

编译、调试中的 lua 命令行:

luac反编译后是空的 luac反编译lua_编译_25

添加引用

最后添加引用,这样每次启动入口程序,就会把引用重新编译

luac反编译后是空的 luac反编译lua_开发语言_26