C++调用lua的实现
jopen
10年前
1.vs下lua环境的配置
下载安装LuaForWindows http://luaforge.net/projects/luaforwindows/
打开vs
tools->options->projects->vc++ directories
executable files 选项添加lua安装以后的路径,我的是 E:\work\lua\Lua5.1
include files 选项添加lua include路径,我的是 E:\work\lua\Lua5.1\include
library files 选项添加lua lib路径,我的是 E:\work\lua\Lua5.1\lib
additional Dependencies 选项加入 lua5.1.lib lua51.lib
2.C++调用lua
C中直接include
#include <lua.h> #include <lualib.h> #include <lauxlib.h>
c++中要加extern "C"
#include "stdafx.h" extern "C" { #include <lua.h> #include <lauxlib.h> #include <lualib.h> } lua_State* L; int _tmain(int argc, _TCHAR* argv[]) { L = lua_open(); luaL_openlibs(L); luaL_dofile(L, "test.lua"); lua_close(L); return 0; }
print("hello world!!")