pil 上的一个例子LUA 编译不过 非常郁闷大家帮忙

stuff990 2006-07-16 09:29:53

调用这个就会出现非法引用内存不知为什么
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;
}



...全文
204 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
stuff990 2006-07-18
  • 打赏
  • 举报
回复
自己顶一下,搞这种不广泛使用的东西好痛苦

3,426

社区成员

发帖
与我相关
我的任务
社区描述
其他开发语言 其他开发语言
社区管理员
  • 其他开发语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧