0

我在接口文件中使用以下代码来重命名全局函数free

%ignore free;
%rename(my_free) free;

但是我没有看到的结果头文件free被重命名为my_free. 我在这里做错什么了吗?上面几行放在接口文件的顶部,分别表示第一行和第二行。我在这里看到了这个。

4

1 回答 1

1

The example you showed seems to work exactly as you'd expect. For example given:

%module test

%ignore free;
%rename(my_free) free;

// Function declaration:
void free();
// Or use %include if you prefer

Running:

swig -Wall -java test.i

Generates test.java as:

public class test {
  public static void my_free() {
    testJNI.my_free();
  }
}

So it has been renamed as expected.

Actually the %ignore is entirely redundant here though, the %rename alone would be sufficient to achieve this result. The order is important though - the %rename supersedes the %ignore and both must be before the declaration of free is seen.

The official documentation is at swig.org, I'd tend to prefer that over other sites. (If you're using SWIG 2.0 there's a lot of extra features for renaming too and you can use %rename to ignore functions: %rename("$ignore") free;)

于 2012-11-03T17:18:46.643 回答