VC要编译LUA文件必须先配置VC编程环境。。我用的是VC6.0,lua 5.1.4版
首先将lua的"lua.h" ,"lualib.h", "lauxlib.h" 这三个放在vc程序include文件夹下
然后将lua的lua5.1.lib放在lib文件夹下就OK了
下面看看我写的一个小例子:
a.cpp
- #include "windows.h"
-
- extern "C"{
- #include "lua.h"
- #include "lualib.h"
- #include "lauxlib.h"
- }
-
-
- #pragma comment(lib,"lua5.1.lib")
-
-
- lua_State * L;
-
- static int clib(lua_State *L)
- {
- char path[MAX_PATH];
- GetCurrentDirectory(MAX_PATH,path);
- lua_pushstring(L,path);
- return 1;
-
- }
-
-
- int main ( int argc, char *argv[] )
- {
- int sum;
-
- L = luaL_newstate();
-
- luaL_openlibs(L);
-
- lua_register(L,"clib",clib);
-
- luaL_dofile(L,"4.lua");
-
- lua_getglobal(L,"run");
-
- lua_pcall(L,0,0,0);
-
- lua_close(L);
- return 0;
- }
LUA文件
- function run()
- print("call running from c")
- print(clib())
- end
-
http://blog.csdn.net/chinazhd/article/details/7772316
|
请发表评论