使用pure_out_value策略和std::string &引用的Luabind函数不可能吗?

我试图从一个函数中返回一个字符串,但它无法编译。当我用 int& 类型替换 std::string& 类型时,它会编译,但我想额外返回一个 std::string,我该怎么做?

在 lua 中:

我正在使用 luabind 0.8.1,最新的 Lua,boost 1.4,VC++ 2008

我得到以下编译器错误(似乎它无法确定 std::string& 的大小?

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

点赞
stackoverflow用户4323
stackoverflow用户4323

我照原样复制了你的代码,加上了 #includes,为其添加了 main() 和一个 lua_State,然后它就差不多编译成功了。然后我只是移除了 luabind::def 行末的逗号,它就编译成功了。我不知道你的错误是否只是这个逗号的问题,但你可以试试下面我列出的代码,并告诉我们结果。

注:在 Linux 上,使用 GCC 4.2.4,Luabind 0.7 和 0.9(预发布版),编译命令为 g++ -c file.cpp

#include <luabind/luabind.hpp>
#include <luabind/out_value_policy.hpp>`

bool luacw_getElementContent( std::string name, std::string& content, bool fromBeginning )
{
    content = "test";
    return false;
}

int main()
{
    lua_State* myLuaState = NULL;
    luabind::module(myLuaState)
    [
        luabind::def("__getElementContent", &luacw_getElementContent, luabind::pure_out_value(_2))
    ]
    //Code ends here: I just removed the comma at the end of the `luabind::def` line.
    ;
}
2009-10-27 01:16:40
stackoverflow用户9657642
stackoverflow用户9657642

luabind::pure_out_value(_3) 修改为 pure_out_value(_2),而不是使用 pure_out_value(_3)

luabind::def("__getElementContent", &luacw_getElementContent, `luabind::pure_out_value(_2)`)
2018-04-30 08:37:27