参考:https://blog.csdn.net/u012963349/article/details/45452383
lua5.3.5源码下载:http://www.lua.org/ftp/
添加到项目中:
将luac.c中的main注释掉。
否则会lua.c中的main重复,导致编译失败。
然后生成之后:
可以加入这样的代码:
int main (int argc, char **argv) {
//int status, result;
//lua_State *L = luaL_newstate(); /* create state */
//if (L == NULL) {
// l_message(argv[0], "cannot create state: not enough memory");
// return EXIT_FAILURE;
//}
//lua_pushcfunction(L, &pmain); /* to call 'pmain' in protected mode */
//lua_pushinteger(L, argc); /* 1st argument */
//lua_pushlightuserdata(L, argv); /* 2nd argument */
//status = lua_pcall(L, 2, 1, 0); /* do the call */
//result = lua_toboolean(L, -1); /* get result */
//report(L, status);
//lua_close(L);
//return (result && status == LUA_OK) ? EXIT_SUCCESS : EXIT_FAILURE;
/* 初始化Lua */
lua_State* L = luaL_newstate();
/* 载入Lua基本库 */
luaL_openlibs(L);
/* 运行脚本 */
luaL_dofile(L, "hello.lua");
/* 清除Lua */
lua_close(L);
system("pause");
}
执行: