【问题标题】:SWIG/Lua typemap for Boost Array in用于 Boost Array 的 SWIG/Lua 类型映射
【发布时间】:2012-09-09 06:42:13
【问题描述】:

我正在尝试构建一个 typemap(in) 用于 C++ boost scoped_arrays。我有采用 boost 数组的 C++ 函数,但我想将它们传递给 Lua 列表。

我看过 Python 的示例,但它们似乎包含太多 Python 特定的代码。

有没有人得到帮助或指向示例以帮助我入门?

【问题讨论】:

    标签: c++ boost lua swig


    【解决方案1】:

    你可能会使用类似的东西:

    %{
    #include <boost/scoped_array.hpp>
    %}
    
    namespace boost {
    
    template<class T>
    class scoped_array {
    public:
        scoped_array();
        ~scoped_array();
    
        void reset();
        void swap(scoped_array& b);
    
        %extend
        {
            scoped_array(unsigned n)
            {
                return new scoped_array<T>(new T[n]);
            }
            T __getitem__(unsigned int idx)
            {
                return (*self)[idx];
            }
            void __setitem__(unsigned int idx,T val)
            {
                (*self)[idx]=val;
            }
        };
    };
    
    }
    

    作为起点。它公开了 boost::scoped_array 的重要部分,并且松散地基于 SWIG 在其标准类型映射库中的 std::vector 实现。

    它添加了特殊的成员函数和一个新的构造函数,同时也分配了一些存储空间。它没有向 SWIG 显示一些定义,因为我在你的目标语言中看不到它们的用途。

    注意:我没有编译并检查了这个。 SWIG 对此很满意,并且生成的包装器看起来很正常。

    【讨论】:

    • 您将如何继续使用普通浮点数组来实现相同的结果? (设置和获取我的意思的项目)
    • 我基本上试图做与这里描述的相同的事情:stackoverflow.com/questions/29724937/…
    猜你喜欢
    • 2017-08-08
    • 1970-01-01
    • 2019-01-25
    • 2016-07-25
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 2021-12-22
    相关资源
    最近更新 更多