我正在尝试移植此代码:
struct SoundIoChannelLayout {
const char *name;
int channel_count;
enum SoundIoChannelId channels[SOUNDIO_MAX_CHANNELS];
};
Run Code Online (Sandbox Code Playgroud)
但是我不知道如何定义的类型channels,并且我知道我不能使用指针,因为最终的结构大小将不一样。
我能够使用crystal_lib自动生成它:
$ cd crystal_lib
$ cat examples/soundio.cr
@[Include("soundio/soundio.h", prefix: %w(SoundIo))]
@[Link("soundio")]
lib LibSoundio
end
$ crystal src/main.cr -- examples/soundio.cr > soundio.cr
Run Code Online (Sandbox Code Playgroud)
所以看起来像这样:
@[Link("soundio")]
lib LibSoundio
MAX_CHANNELS = 24
struct ChannelLayout
name : LibC::Char*
channel_count : LibC::Int
channels : ChannelId[MAX_CHANNELS]
end
enum ChannelId
Invalid = 0
FrontLeft = 1
FrontRight = 2
FrontCenter = 3
# ...
end
# ...
end
Run Code Online (Sandbox Code Playgroud)
注意:您可能需要手动更新结果文件,因为crystal_lib仍处于试验阶段。
| 归档时间: |
|
| 查看次数: |
100 次 |
| 最近记录: |