我有一个第三方 C 库,它定义了一个类似于:
struct myStruct {
int a;
int b;
char str1[32];
char str2[32];
};
还有一个函数,它接受一个指向这个结构的指针并填充它。我需要我的 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)?
}
还有一个本地调用,例如:
sub fillStruct(myStruct) 是原生的('test_lib') { ... } 我的 $struct = myStruct.new(); 填充结构($结构);# 到目前为止我尝试过的任何变体都会出现 seg 错误
我怎样才能使这项工作?