使用静态链接的方式
#include <stdio.h> #include <stdlib.h> #include <string.h> #ifdef __cplusplus extern "C" { #endif #include "lua/include/lua.h" #include "lua/include/lauxlib.h" #include "lua/include/lualib.h" #pragma comment (lib, "lua/lib/lua5.2.3-static.lib") #ifdef __cplusplus } #endif int main(void) { char buffer[256]; int error; lua_State *L = luaL_newstate(); /*打开lua */ luaL_openlibs(L); /*打开标准库*/ while(fgets(buffer,sizeof(buffer),stdin)!=NULL) { error = luaL_loadbuffer(L,buffer,strlen(buffer),"line") || lua_pcall(L,0,0,0); if(error) { fprintf(stderr,"%s", lua_tostring(L,-1)); lua_pop(L,1);/*从栈中弹出错误信息*/ } } lua_close(L); return 0; }
原文地址:http://blog.csdn.net/haifengzhilian/article/details/35992915