参考帖子:https://www.freesion.com/article/54861371918/
自己简单的总结了一下。
-
去官网下载任意一个lua包,经过测试lua5.1.1编译之后的lib文件,无法运行。 -
新建一个Visual Studio的Visual C++项目,编译方式为静态库。   -
在项目中的头文件和源文件中,分别把对应lua解压包中src的.h和.c文件导入进来。注意源文件不需要导入lua.h和luac.h。 -
编译  -
在Release目录下,将xxx.lib文件,复制到指定目录,我是直接复制在lua原本的目录。
 6. 在自己的项目中的【属性】\【c/c++】\【常规】中,设置附加包含的目录。
 7. 在【属性】\【链接器】\【常规-附加库目录】和【输入-附加依赖】中,分别导入lua lib所在的文件,以及lua lib的名字。
大功告成
测试
#include<iostream>
extern "C" {
#include <lauxlib.h>
#include <lualib.h>
}
using namespace std;
int main() {
cout << "123" << endl;
lua_State* lua = luaL_newstate();
luaL_openlibs(lua);
luaL_dofile(lua, "main.lua");
lua_close(lua);
system("pause");
return 0;
}
print("hello world")

|