vs2012 简单的lua解释器

来源:互联网 发布:淘宝图片轮播效果 编辑:程序博客网 时间:2024/06/17 11:54
1. 将lua的include目录添加到vs2012的包含目录中
2. 将lua的lib目录添加到vs2012的库目录中
3. 代码作用:将输入的程序解释为lua代码。
#include "stdafx.h"#include <stdio.h>#include <string.h>extern "C"{#include "lua.h"#include "lualib.h"#include "lauxlib.h"}#pragma comment(lib,"lua51.lib")// 简单的lua解释器int _tmain(int argc, _TCHAR* argv[]){char buff[256] = { 0 };int error;lua_State *L = luaL_newstate();  // 打开lualuaL_openlibs(L);                // 打开标准库while(fgets(buff,sizeof(buff),stdin) != NULL){error = luaL_loadbuffer(L,buff,strlen(buff),"line") || lua_pcall(L,0,0,0);if(error){fprintf(stdout,"error:%s\n",lua_tostring(L,-1)); // 打印出错信息lua_pop(L,-1);  // 从栈中删除这个错误消息}}lua_close(L);return 0;}运行结果:
原创粉丝点击