lua 模块中的新结构在编译阶段不可访问

我是一个 lua 脚本的新手。我尝试将一些现有的 C++ 类导出到 lua,并使用额外的结构和方法进行扩展。

%module custom_matching

%include "std_vector.i"
%include "std_pair.i"

%inline %{
#include "Matching.h"
%}

%typemap(out) boost::optional<double> %{
if($1)
    $result = *$1;
else {
    $result = nil;
}
%}

namespace Matching{
        class Matching {
            public:
            Matching(double someArg = 1e-4);

            boost::optional<double> onMsg(double forwardDistance = 0.);

            void setVerbose(bool verbose);
        };

        %extend Matching {
            boost::optional<double> onPoseMsg(const Custom3dPoint &pose) {
                std::cout << "onPoseMsg\n";
                return boost::none;
            }
        }

        struct Custom3dPoint {
            double x, y, z;
        };
}

首先,我收到了以下错误消息: 错误:'Custom3dPoint'尚未声明。

我还想知道,在 lua 中包装 boost::optional 是否能正常工作,并且在实例化类时将使用默认参数。

Swig 3.0

点赞