在Xcode项目中嵌入Lua

我在 Xcode 4 中使用 Lua 5.2.0 遇到了问题。我使用 make 构建它,链接到 liblua.a,添加了头文件路径,并使用 Extern "C" 引用它。我没有收到链接器错误。然而,当我运行这段代码时:

#include <iostream>

extern "C" {
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
}

int main (int argc, char *argv[])
{
    lua_State *ls = lua_newstate(0, 0);

    lua_close(ls);
    return 0;
}

我在第 11 行收到 Thread 1: EXC_BAD_ACCESS (code 1, address=0x0) 错误。我认为这告诉我我试图调用不存在的内容。非常感谢任何帮助!

谢谢, Marc

原文链接 https://stackoverflow.com/questions/10365020

点赞
stackoverflow用户107090
stackoverflow用户107090

你正在将一个空的内存分配函数传递给 lua_newstate。难怪会崩溃。也许你想使用 luaL_newstate

2012-04-28 15:45:37