lua 学习笔记12
/******************/ 在c++中使用lua/******************/费了九牛二虎之力,总算可以在vs 2003的c++环境中使用lua了。方法如下:1、解压缩下载的lua原文件包 ,把其ect目录下的luavs.bat,拷贝到lua目录下,在vs2003的命令行工具中运行它,生成编译好的文件。 2、在vs2003中建立一个控制台项目,把刚才生成的一堆src目录下的文件拷到这个项目下,新建一个main.cpp文件,写入如下内容: #include <stdio.h>#include <string.h> extern"C"{#include "lua.h"#include "lauxlib.h"#include "lualib.h"} int main(void){ char buff[256]; int error; lua_State *L = lua_open(); /* opens Lua */ luaopen_base(L); /* opens the basic library */ luaopen_table(L); /* opens the table library */ luaopen_io(L); /* opens the I/O library */ luaopen_string(L); /* opens the string lib. */ luaopen_math(L); /* opens the math lib. */ while (fgets(buff, sizeof(buff), stdin) != NULL) { error = luaL_loadbuffer(L, buff, strlen(buff), "line") || lua_pcall(L, 0, 0, 0); …