Ruby で FFI 構造体を設定する初心者の問題があります。私がやりたいことは、FFI::Struct オブジェクトで文字列プロパティを設定して、C 文字列へのポインターを渡すことです。
class SpSessionConfig < FFI::Struct
layout :api_version, :int,
:cache_location, :string,
:settings_location, :string,
:application_key, :pointer,
:application_key_size, :int,
:user_agent, :string,
:sp_session_callbacks, :pointer,
:user_data, :pointer
end
end
sessionConf = SpotifyLibrary::SpSessionConfig.new()
puts sessionConf # => '#<SpotifyLibrary::SpSessionConfig:0x9acc00c>'
sessionConf[:api_version] = 1
puts "Api Version: #{sessionConf[:api_version]}"
myTempDir = "tmp"
sessionConf[:cache_location] = myTempDir # !Error!
しかし、コードを実行すると、次のエラーが発生します。
jukebox.rb:44:in `[]=': Cannot set :string fields (ArgumentError)
from jukebox.rb:44:in `<main>'
だから、ここからどこへ行けばいいのかわからない。
また、このテーマに関する適切なドキュメントやチュートリアルを知っている場合は、返信を残してください! これまでのところ、 Project Kenaiに関する wiki ドキュメントは 非常に有用であることがわかりました。
ありがとう!
文字列データ メンバーを [:char, 5] として宣言しようとしましたが、別のエラーが発生します。
jukebox.rb:44:in `put': put not supported for FFI::StructLayoutBuilder::ArrayField_Signed8_3 (ArgumentError)
from jukebox.rb:44:in `[]='
from jukebox.rb:44:in `<main>
メモリ ポインター型を試してみる良い提案があり、今日の仕事の後に試してみます。