1

関数から文字列を返そうとしていますが、コンパイルできません。std::string& タイプを int& に置き換えるとコンパイルされますが、さらにブール値に std::string を返したいのですが、どうすればよいですか?

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

...

luabind::module(myLuaState) [
   luabind::def("__getElementContent", &luacw_getElementContent, luabind::pure_out_value(_2))
];

ルアで:

success, content = __getElementContent("a", true)

luabind 0.8.1、最新の Lua、boost 1.4、VC++ 2008 を使用しています。

次のコンパイラ エラーが発生します ( std::string& のサイズを特定できないようです ?


1>d:\osxdata\libs\luabind\luabind-0.8.1\luabind\out_value_policy.hpp(78) : error C2784: 'luabind::detail::char_array<sizeof(identity<T>::type)> luabind::detail::indirect_sizeof_test(luabind::detail::by_value<T>)' : could not deduce template argument for 'luabind::detail::by_value<T>' from 'luabind::detail::by_reference<T>'
1>        with
1>        [
1>            T=std::string
1>        ]
1>        d:\osxdata\libs\luabind\luabind-0.8.1\luabind\out_value_policy.hpp(71) : see declaration of 'luabind::detail::indirect_sizeof_test'
1>        d:\osxdata\libs\luabind\luabind-0.8.1\luabind\out_value_policy.hpp(228) : see reference to class template instantiation 'luabind::detail::indirect_sizeof<T>' being compiled
1>        with
1>        [
1>            T=a1
1>        ]
1>        d:\osxdata\libs\boost\src\boost\mpl\aux_\preprocessed\plain\apply_wrap.hpp(49) : see reference to class template instantiation 'luabind::detail::pure_out_value_policy<BOOST_PP_ITERATION_0,Policies>::apply<T,Direction>' being compiled
1>        with
1>        [
1>            BOOST_PP_ITERATION_0=2,
1>            Policies=luabind::detail::null_type,
1>            T=a1 ,
1>            Direction=luabind::detail::lua_to_cpp
1>        ]
1>        d:\osxdata\libs\boost\src\boost\preprocessor\iteration\detail\local.hpp(37) : see reference to class template instantiation 'boost::mpl::apply_wrap2<F,T1,T2>' being compiled
1>        with
1>        [
1>            F=p1,
1>            T1=a1,
1>            T2=luabind::detail::lua_to_cpp
1>        ]
1>        d:\osxdata\libs\luabind\luabind-0.8.1\luabind\detail\call.hpp(48) : see reference to function template instantiation 'int luabind::detail::invoke_normal<bool(__cdecl *)(std::string,std::string &,bool),boost::mpl::vector4<T0,T1,T2,T3>,Policies>(lua_State *,const F &,Signature,const Policies &,boost::mpl::long_<N>,boost::mpl::false_)' being compiled
1>        with
1>        [
1>            T0=bool,
1>            T1=std::string,
1>            T2=std::string &,
1>            T3=bool,
1>            Policies=luabind::detail::policy_cons<luabind::detail::pure_out_value_policy<2,luabind::detail::null_type>,luabind::detail::null_type>,
1>            F=bool (__cdecl *)(std::string,std::string &,bool),
1>            Signature=boost::mpl::vector4<bool,std::string,std::string &,bool>,
1>            N=3
1>        ]
1>        d:\osxdata\libs\luabind\luabind-0.8.1\luabind\detail\call.hpp(58) : see reference to function template instantiation 'int luabind::detail::invoke0<bool(__cdecl *)(std::string,std::string &,bool),boost::mpl::vector4<T0,T1,T2,T3>,Policies,boost::is_void<T>>(lua_State *,const F &,Signature,const Policies &,IsVoid,boost::mpl::false_)' being compiled
1>        with
1>        [
1>            T0=bool,
1>            T1=std::string,
1>            T2=std::string &,
1>            T3=bool,
1>            Policies=luabind::detail::policy_cons<luabind::detail::pure_out_value_policy<2,luabind::detail::null_type>,luabind::detail::null_type>,
1>            T=bool,
1>            F=bool (__cdecl *)(std::string,std::string &,bool),
1>            Signature=boost::mpl::vector4<bool,std::string,std::string &,bool>,
1>            IsVoid=boost::is_void<bool>
1>        ]
1>        d:\osxdata\libs\luabind\luabind-0.8.1\luabind\make_function.hpp(31) : see reference to function template instantiation 'int luabind::detail::invoke<bool(__cdecl *)(std::string,std::string &,bool),boost::mpl::vector4<T0,T1,T2,T3>,luabind::detail::policy_cons<H,T>>(lua_State *,const F &,Signature,const Policies &)' being compiled
1>        with
1>        [
1>            T0=bool,
1>            T1=std::string,
1>            T2=std::string &,
1>            T3=bool,
1>            H=luabind::detail::pure_out_value_policy<2,luabind::detail::null_type>,
1>            T=luabind::detail::null_type,
1>            F=bool (__cdecl *)(std::string,std::string &,bool),
1>            Signature=boost::mpl::vector4<bool,std::string,std::string &,bool>,
1>            Policies=luabind::detail::policy_cons<luabind::detail::pure_out_value_policy<2,luabind::detail::null_type>,luabind::detail::null_type>
1>        ]
1>        d:\osxdata\libs\luabind\luabind-0.8.1\luabind\make_function.hpp(30) : while compiling class template member function 'int luabind::detail::function_invoke<F,Signature,Policies>::operator ()(lua_State *) const'
1>        with
1>        [
1>            F=bool (__cdecl *)(std::string,std::string &,bool),
1>            Signature=boost::mpl::vector4<bool,std::string,std::string &,bool>,
1>            Policies=luabind::detail::policy_cons<luabind::detail::pure_out_value_policy<2,luabind::detail::null_type>,luabind::detail::null_type>
1>        ]
1>        d:\osxdata\libs\luabind\luabind-0.8.1\luabind\make_function.hpp(76) : see reference to class template instantiation 'luabind::detail::function_invoke<F,Signature,Policies>' being compiled
1>        with
1>        [
1>            F=bool (__cdecl *)(std::string,std::string &,bool),
1>            Signature=boost::mpl::vector4<bool,std::string,std::string &,bool>,
1>            Policies=luabind::detail::policy_cons<luabind::detail::pure_out_value_policy<2,luabind::detail::null_type>,luabind::detail::null_type>
1>        ]
1>        d:\osxdata\libs\luabind\luabind-0.8.1\luabind\function.hpp(28) : see reference to function template instantiation 'luabind::adl::object luabind::make_function<bool(__cdecl *)(std::string,std::string &,bool),boost::mpl::vector4<T0,T1,T2,T3>,Policies>(lua_State *,F,Signature,Policies)' being compiled
1>        with
1>        [
1>            T0=bool,
1>            T1=std::string,
1>            T2=std::string &,
1>            T3=bool,
1>            Policies=luabind::detail::policy_cons<luabind::detail::pure_out_value_policy<2,luabind::detail::null_type>,luabind::detail::null_type>,
1>            F=bool (__cdecl *)(std::string,std::string &,bool),
1>            Signature=boost::mpl::vector4<bool,std::string,std::string &,bool>
1>        ]
1>        d:\osxdata\libs\luabind\luabind-0.8.1\luabind\function.hpp(27) : while compiling class template member function 'void luabind::detail::function_registration<F,Policies>::register_(lua_State *) const'
1>        with
1>        [
1>            F=bool (__cdecl *)(std::string,std::string &,bool),
1>            Policies=luabind::detail::policy_cons<luabind::detail::pure_out_value_policy<2,luabind::detail::null_type>,luabind::detail::null_type>
1>        ]
1>        d:\osxdata\libs\luabind\luabind-0.8.1\luabind\function.hpp(50) : see reference to class template instantiation 'luabind::detail::function_registration<F,Policies>' being compiled
1>        with
1>        [
1>            F=bool (__cdecl *)(std::string,std::string &,bool),
1>            Policies=luabind::detail::policy_cons<luabind::detail::pure_out_value_policy<2,luabind::detail::null_type>,luabind::detail::null_type>
1>        ]
1>        d:\osxdata\libs\scintillawrapper\mainfrm.cpp(191) : see reference to function template instantiation 'luabind::scope luabind::def<bool(__cdecl *)(std::string,std::string &,bool),luabind::detail::policy_cons<H,T>>(const char *,F,const Policies &)' being compiled
1>        with
1>        [
1>            H=luabind::detail::pure_out_value_policy<2,luabind::detail::null_type>,
1>            T=luabind::detail::null_type,
1>            F=bool (__cdecl *)(std::string,std::string &,bool),
1>            Policies=luabind::detail::policy_cons<luabind::detail::pure_out_value_policy<2,luabind::detail::null_type>,luabind::detail::null_type>
1>        ]
1>d:\osxdata\libs\luabind\luabind-0.8.1\luabind\out_value_policy.hpp(78) : error C2784: 'luabind::detail::char_array<sizeof(identity<T>::type)> luabind::detail::indirect_sizeof_test(luabind::detail::by_const_pointer<T>)' : could not deduce template argument for 'luabind::detail::by_const_pointer<T>' from 'luabind::detail::by_reference<T>'
1>        with
1>        [
1>            T=std::string
1>        ]
1>        d:\osxdata\libs\luabind\luabind-0.8.1\luabind\out_value_policy.hpp(68) : see declaration of 'luabind::detail::indirect_sizeof_test'
1>d:\osxdata\libs\luabind\luabind-0.8.1\luabind\out_value_policy.hpp(78) : error C2784: 'luabind::detail::char_array<sizeof(identity<T>::type)> luabind::detail::indirect_sizeof_test(luabind::detail::by_pointer<T>)' : could not deduce template argument for 'luabind::detail::by_pointer<T>' from 'luabind::detail::by_reference<T>'
1>        with
1>        [
1>            T=std::string
1>        ]
1>        d:\osxdata\libs\luabind\luabind-0.8.1\luabind\out_value_policy.hpp(65) : see declaration of 'luabind::detail::indirect_sizeof_test'
1>d:\osxdata\libs\luabind\luabind-0.8.1\luabind\out_value_policy.hpp(78) : error C2784: 'luabind::detail::char_array<sizeof(identity<T>::type)> luabind::detail::indirect_sizeof_test(luabind::detail::by_const_reference<T>)' : could not deduce template argument for 'luabind::detail::by_const_reference<T>' from 'luabind::detail::by_reference<T>'
1>        with
1>        [
1>            T=std::string
1>        ]
1>        d:\osxdata\libs\luabind\luabind-0.8.1\luabind\out_value_policy.hpp(62) : see declaration of 'luabind::detail::indirect_sizeof_test'
1>d:\osxdata\libs\luabind\luabind-0.8.1\luabind\out_value_policy.hpp(78) : error C2893: Failed to specialize function template 'luabind::detail::char_array<sizeof(identity<T>::type)> luabind::detail::indirect_sizeof_test(luabind::detail::by_reference<T>)'
1>        With the following template arguments:
1>        'std::string'
1>d:\osxdata\libs\luabind\luabind-0.8.1\luabind\out_value_policy.hpp(78) : error C2866: 'luabind::detail::indirect_sizeof<T>::value' : a const static data member of a managed type must be initialized at the point of declaration
1>        with
1>        [
1>            T=a1
1>        ]
1>d:\osxdata\libs\luabind\luabind-0.8.1\luabind\out_value_policy.hpp(228) : error C2975: 'Size' : invalid template argument for 'luabind::detail::pure_out_value_converter', expected compile-time constant expression
1>        d:\osxdata\libs\luabind\luabind-0.8.1\luabind\out_value_policy.hpp(163) : see declaration of 'Size'
1>d:\osxdata\libs\luabind\luabind-0.8.1\luabind\out_value_policy.hpp(211) : warning C4200: nonstandard extension used : zero-sized array in struct/union
1>        Cannot generate copy-ctor or copy-assignment operator when UDT contains a zero-sized array
1>        d:\osxdata\libs\boost\src\boost\preprocessor\iteration\detail\local.hpp(37) : see reference to class template instantiation 'luabind::detail::pure_out_value_converter<Size,Policies>' being compiled
1>        with
1>        [
1>            Size=0,
1>            Policies=luabind::detail::null_type
1>        ]
1>d:\osxdata\libs\boost\src\boost\preprocessor\iteration\detail\local.hpp(37) : warning C4815: 'c1' : zero-sized array in stack object will have no elements (unless the object is an aggregate that has been aggregate initialized)
4

2 に答える 2

4

私はあなたのコードを逐語的にコピーし、 を追加し、と#includesを作成し、ほぼコンパイルしました。次に、行末のカンマを削除してコンパイルしました。カンマだけが問題だったのかどうかはわかりませんが、以下の内容を試してお知らせください。main()lua_Stateluabind::def

注: g++ -c file.cppLinux では、GCC 4.2.4、Luabind 0.7、および 0.9 (プレリリース) でコンパイルされています。

#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))
    ];
}
于 2009-10-27T01:16:40.933 に答える