通路我的個人部落格 秋碼個人部落格
打開VS2013 IDE,建立一個空的控制台項目。

然後對項目進行引用庫的配置。
這是我編譯Lua源碼所得到的靜态庫。
在這就是附加庫的位置。
也就是LuaLib.lib所在的目錄。
最後配置Lua源碼目錄,因為需要用到Lua頭檔案。
在源檔案下建立一個cpp檔案,main.cpp檔案内容如下:
#include <iostream>
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#include "lua.hpp"
#include "lualib.h"
#include "lauxlib.h"
}
#else
#include "lua.hpp"
#include "lualib.h"
#include "lauxlib.h"
#endif
/*Lua解釋器指針*/
lua_State* L;
int main(int argc, char* argv[]){
L = luaL_newstate();
/* 載入Lua基本庫 */
luaL_openlibs(L);
/* 運作腳本 */
luaL_dofile(L, "addFun.lua");
/* 清除Lua */
lua_close(L);
system("pause");
return 0;
}
addfun.lua檔案如下:
print("lua script addfun.lua have been load ")
function showinfo()
print("welcome to lua world ")
end
function showstr(str)
print("The string you input is " .. str)
end
function add(x,y)
return x+y;
end
編譯生成。
項目結構如下: