SWIG/Lua typemap for Boost Array in

SWIG/Lua typemap for Boost Array in

本文关键字:Boost Array in for typemap Lua SWIG      更新时间:2023-10-16

我正在尝试构建一个类型图(in)以用于C++提升scoped_arrays。我有C++函数来获取提升数组,但我想将它们传递给 Lua 列表。

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

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

你可以使用这样的东西:

%{
#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对此感到满意,生成的包装器看起来很理智。