我有一个第三方C库,它定义了一个类似于的结构:
struct myStruct {
int a;
int b;
char str1[32];
char str2[32];
};
Run Code Online (Sandbox Code Playgroud)
还有一个函数,它接受一个指向这个结构的指针并填充它.我需要我的Perl6本机调用来提供该结构,然后读取结果.
到目前为止,我已经在Perl6中定义了结构:
class myStruct is repr('CStruct') {
has int32 $.a;
has int32 $.b;
has Str $.str1; # Option A: This won't work as Perl won't know what length to allocate
has CArray[uint8] $.str2; # Option B: This makes more sense, but again how to define length?
# Also, would this allocate the array in place, or
# reference an array that is separately allocated (and therefore not valid)?
}
Run Code Online (Sandbox Code Playgroud)
和本地电话一样:
sub fillStruct(myStruct) is native('test_lib') { ... }
my $struct = myStruct.new();
fillStruct($struct); # Gives a seg fault with any variation I've tried so far
我怎样才能做到这一点?
| 归档时间: |
|
| 查看次数: |
254 次 |
| 最近记录: |