使用SWIG从C函数中获取参数

时间:2017-10-14 00:07:14

标签: python swig

我有以下SWIG文件(当然简化):

var header: UIView!
var tableView:UITableView!
var offset:CGFloat = 0

override public func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    // Touches Began. Disable user activity on UITableView
    if let touch = touches.first {
        // Get the point where the touch started
        let point = touch.location(in: self.header)
        offset = point.x
    }
}

override public func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
    if let touch = touches.first {

        // Get the point where the touch is moving in header
        let point = touch.location(in: self.header)

        // Calculate the movement of finger
        let x:CGFloat = offset - point.x
        if x > 0 {
            // Move cells by offset
            moveCellsBy(x: x)
        }

        // Set new offset
        offset = point.x
    }
}

override public func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
    // Reset offset when user lifts finter
    offset = 0
}

func moveCellsBy(x: CGFloat) {
    // Move each visible cell with the offset
    for cell in self.tableView.visibleCells {
        // Place in animation block for smoothness
        UIView.animate(withDuration: 0.05, animations: {
            cell.contentView.frame = CGRect(x: cell.contentView.frame.origin.x - x, y: cell.contentView.frame.origin.y, width: cell.contentView.frame.size.width, height: cell.contentView.frame.size.height)
        })
    }
}

我希望Python函数签名为:

typedef int64_t SuiteSparse_long;

%apply SuiteSparse_long  *OUTPUT {
     SuiteSparse_long  *lnz,
     SuiteSparse_long  *unz,
     SuiteSparse_long  *n_row,
     SuiteSparse_long  *n_col,
     SuiteSparse_long  *nz_udiag
 };

SuiteSparse_long umfpack_dl_get_lunz
(
    SuiteSparse_long *lnz,
    SuiteSparse_long *unz,
    SuiteSparse_long *n_row,
    SuiteSparse_long *n_col,
    SuiteSparse_long *nz_udiag,
    void *Numeric
) ;

但是,实际的Python函数签名是

umfpack_zl_get_lunz(void * Numeric) -> (SuiteSparse_long, SuiteSparse_long lnz, SuiteSparse_long unz, SuiteSparse_long n_row, SuiteSparse_long n_col)

有趣的是,当我umfpack_zl_get_lunz(SuiteSparse_long * lnz, SuiteSparse_long * unz, SuiteSparse_long * n_row, SuiteSparse_long * n_col, SuiteSparse_long * nz_udiag, void * Numeric) -> SuiteSparse_long 时,它会起作用,但不适用于typedef long SuiteSpare_long。 SWIG不支持int64_t吗?

0 个答案:

没有答案