2016-02-11 55 views
1

我是Lua新手,尤其是Luabind新手。當我試圖編譯(鏗鏘++),我的第一個文件使用Luabind:如何使用LUA_COMPAT_ALL?

#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); 
    } 

我的error messages整個堆。

所以,我做了一些環顧四周,我發現它與我的Lua版本是5.2 VS 5.1做,發現解決方案是LUA_COMPAT_ALL(這是我在Lua project compiling with errors (luabind)發現)。

不幸的是,當談到Lua的時候,我有些厭倦了;所以,我不知道我把它放在哪裏。

我希望我的問題是不是太傻:)

+1

Lua 5.1和5.2有一些主要的不同之處。如果你致力於Lua 5.2,看起來好像有人已經採用了Luabind,並且創建了一個與5.2更兼容的新版本。 https://github.com/rpavlik/luabind也許試試? –

+0

@AdamB我按照提示安裝了boost(通過brew),但是當我'bjam install'時它返回[errors](http://pastebin.com/QJzjaVAe) – Julian

回答

1

只需定義它在你的代碼應該工作,因爲在Lua中源(CTRL + F爲 「LUA_COMPAT_ALL」)告知:http://www.lua.org/source/5.2/luaconf.h.html

(它可能已經在手冊中,但稍後從中刪除)

+0

@EinstienK我加了'#include ''#定義LUA_COMPAT_AL',我仍然得到錯誤http://pastebin.com/bx8vxiUW – Julian

+0

@Julian首先,它被命名爲LUA_COMPAT_AL ** L **,第二,你必須在**之前定義它**包括_luaconf。 H_。愛因斯坦K目前是對的,但並不認爲你缺乏C經驗。 – Youka

+0

我修復了它,但不幸的是它返回了同樣的錯誤。 – Julian