如何使用 LUA_COMPAT_ALL?

我是新手 Lua 用户,对 Luabind 更是不熟悉。当我尝试使用 Luabind 编译我的第一个文件(使用 Clang++)时:

    #define LUA_COMPAT_ALL
    #include <luabind/luabind.hpp>
    #include <luaconf.h>
    #include <iostream>

    int main() {

      lua_State *myLuaState = luaL_newstate();

      luabind::open(myLuaState);

      luaL_dostring(
        myLuaState,
        "function add(first, second)\n"
        "  return first + second\n"
        "end\n"
      );
      std::cout << "Result: "
           << luabind::call_function<int>(myLuaState, "add", 2, 3)
           << std::endl;

      lua_close(myLuaState);
    }

我收到了一串 错误消息

于是我去查了一下,发现这与我的 Lua 版本是 5.2 而非 5.1 有关,并且找到了解决方法:LUA_COMPAT_ALL(我在 Lua project compiling with errors (luabind) 上找到的)。

不幸的是,我对 Lua 不太了解,不知道应该放在哪里。

希望我的问题不太蠢 :)

点赞
用户5352026
用户5352026

在 Lua 源代码中可以找到定义(使用 CTRL+F 键查找 "LUA_COMPAT_ALL"),在代码中设置即可正常工作:http://www.lua.org/source/5.2/luaconf.h.html

(可能曾经在手册中提到,但后来被删除了)

2016-02-11 09:09:26