pil 上的一个例子LUA 编译不过 非常郁闷大家帮忙
调用这个就会出现非法引用内存不知为什么
luaopen_io(L);
另外我不懂open系列函数open一个io 但是他的包在哪里呢,谢谢
代码如下
VC6+LUA5.1
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
void error (lua_State *L, const char *fmt, ...) {
va_list argp;
va_start(argp, fmt);
vsprintf(stderr, fmt,argp);
va_end(argp);
lua_close(L);
exit(EXIT_FAILURE);
}
void load (char *filename, int *width, int *height) {
lua_State *L = lua_open();
luaopen_base(L);
luaopen_io(L);
luaopen_string(L);
luaopen_math(L);
printf("error\n");
if (luaL_loadfile(L, filename) || lua_pcall(L, 0, 0, 0))
error(L, "cannot run configuration file: %s",
lua_tostring(L, -1));
lua_getglobal(L, "width");
lua_getglobal(L, "height");
if (!lua_isnumber(L, -2))
error(L, "`width' should be a number\n");
if (!lua_isnumber(L, -1))
error(L, "`height' should be a number\n");
*width = (int)lua_tonumber(L, -2);
*height = (int)lua_tonumber(L, -1);
lua_close(L);
}
int main()
{
int width=0, height=0;
char filename[]="config";
load("filename",&width, &height);
printf("width = %d, height = %d,\n ",width, height);
return 1;
}