Embedding Lua with Xcode

Embedding Lua with Xcode

本文关键字:Xcode with Lua Embedding      更新时间:2023-10-16

我在让Lua 5.2.0在Xcode 4中工作时遇到了问题。我使用 liblua.a 中链接的make构建了它,添加了标头路径,并将其包含在 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)。我假设这是在告诉我,我实际上是在试图对不存在的东西发出呼吁。任何帮助将不胜感激!

谢谢马克

您正在将 NULL 内存分配函数传递给 lua_newstate 。难怪它会崩溃。也许你想使用luaL_newstate