【问题标题】:can't use instance variables at the top level不能在顶层使用实例变量
【发布时间】:2017-04-25 20:01:33
【问题描述】:

我正在尝试让音频播放器与 Crystal 配合使用。互联网表明 portaudio 是播放音频的最佳 C 库,并且由于没有原生的 Crystal 库,它似乎是最好的选择。

有人已经投入了大部分工作来将 portaudio API 绑定到 Crystal,但是该项目已经过时并且似乎已被 Crystal 更新破坏。我认为修复别人的绑定比从头开始做所有事情更容易。

这是一个不必要的冗长介绍。当我尝试编译crystal-portaudio 时,出现以下错误:

$ crystal src/portaudio.cr                                                                                                                 ~/sw/crystal/crystal-portaudio (master)
Error in src/portaudio.cr:1: while requiring "./portaudio/*"

require "./portaudio/*"
^

in src/portaudio/device.cr:2: while requiring "./host_api"

require "./host_api"
^

in src/portaudio/host_api.cr:5: can't use instance variables at the top level

    delegate :device_count, :default_input_device, :default_output_device, :type, @info
                                                                                  ^~~~~

Link to offending line.

【问题讨论】:

    标签: crystal-lang


    【解决方案1】:

    这是使 crystal speccrystal samples/list.cr 与 Crystal 0.22 一起编译和运行的最小补丁,但是该分片似乎还需要更多的工作才能真正可用。

    diff --git a/spec/portaudio_spec.cr b/spec/portaudio_spec.cr
    index d8171a9..049a294 100644
    --- a/spec/portaudio_spec.cr
    +++ b/spec/portaudio_spec.cr
    @@ -1,6 +1,6 @@
     require "./spec_helper"
    
    -describe Portaudio do
    +describe Pa do
       # TODO: Write tests
    
       it "works" do
    diff --git a/src/portaudio/device.cr b/src/portaudio/device.cr
    index f5ec4f3..cf999ee 100644
    --- a/src/portaudio/device.cr
    +++ b/src/portaudio/device.cr
    @@ -3,13 +3,13 @@ require "./host_api"
    
     module Pa
       class Device
    -    delegate :max_input_channels, :max_output_channels, @info
    -    delegate :default_low_input_latency, :default_low_output_latency, @info
    -    delegate :default_high_input_latency, :default_high_output_latency, @info
    -    delegate :default_sample_rate, @info
    +    delegate :max_input_channels, :max_output_channels, to: @info
    +    delegate :default_low_input_latency, :default_low_output_latency, to: @info
    +    delegate :default_high_input_latency, :default_high_output_latency, to: @info
    +    delegate :default_sample_rate, to: @info
         getter id
    
    -    def initialize(@id, @info)
    +    def initialize(@id : Pa::DeviceIndex, @info : LibPortAudio::DeviceInfo)
         end
    
         def name
    diff --git a/src/portaudio/host_api.cr b/src/portaudio/host_api.cr
    index de3b521..9a95ec2 100644
    --- a/src/portaudio/host_api.cr
    +++ b/src/portaudio/host_api.cr
    @@ -2,9 +2,9 @@ require "./lib"
    
     module Pa
       class HostApi
    -    delegate :device_count, :default_input_device, :default_output_device, :type, @info
    +    delegate :device_count, :default_input_device, :default_output_device, :type, to: @info
    
    -    def initialize(@info)
    +    def initialize(@info : LibPortAudio::HostApiInfo)
         end
    
         def name
    

    【讨论】:

      猜你喜欢
      • 2017-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-07
      • 2022-10-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多