Ruby C拡張を実装しました(つまり、RubyスクリプトからC関数を呼び出します)以下は、ファイル「cFile.c」からcで実装された関数です
#include<stdio.h>
static VALUE cFunction(VALUE self, VALUE src)
{
if(TYPE(str) == T_STRUCT)
{
printf(" variable str is of STRUCT type \n");
}
// here how can i get the members of structure variable "str"
return Qnil;
}
void Init_MyRuby()
{
VALUE MRuby = rb_define_module("MyRuby");
rb_define_singleton_method(MRuby, "cFunction", cFunction, 1);
}
以下は、struct 型の変数を渡して functon() メソッドを呼び出す ruby スクリプトのコードです。client.rb:
require 'cFile'
customer = Struct.new( "Customer", :name, :address, :zip )
joe = customer.new( "JoeSmith", "123 Maple, Anytown NC", 12345 )
MyRuby::cFunction(joe)
cFunction() で構造体メンバー (名前、アドレスなど) を取得する方法を教えてもらえますか? 前もって感謝します