From: pere.noel@... (=?ISO-8859-1?Q?Une_b=E9vue?=) Date: 2006-08-09T19:35:11+09:00 Subject: Re: FOUND was (Re: Init_xxx(with arg ??) in C for ruby ext ???) ts wrote: > Post your *complete* source > > U> where the C counterpart being : > U> VALUE m_alias_path(VALUE self) { > U> // char *alias_path = "/path/to/something/undefined"; > U> return rb_str_new2((char *) alias_path); > U> } > > This is just a nonsense. You define an instance variable @alias_path then > you try to retrieve a local C variable alias_path rather than the instance > variable. ok thanks a lot for your clear answer ;-) --- RAliasFile.h-------------------------------------------------------- void Init_raliasfile(); VALUE m_raliasfile_init(VALUE self, VALUE alias_path); VALUE m_raliasfile_new(VALUE self, VALUE alias_path); VALUE m_set_alias_path(VALUE self, VALUE alias_path); VALUE m_alias_path(VALUE self); VALUE m_orig_path(VALUE self); VALUE m_is_alias_file(VALUE self); VALUE m_is_alias_file_broken(VALUE self); VALUE m_is_folder(VALUE self); VALUE m_is_data_file(VALUE self); VALUE m_version(VALUE self); ------------------------------------------------------------------------ --- RAliasFile.c-------------------------------------------------------- // // RAliasFile.c // #include "ruby.h" #include "RAliasFile.h" VALUE RAliasFile = Qnil; VALUE cRAliasFile; VALUE alias_path; /**/ struct RAliasFile { VALUE alias_path; char *orig_path; int alias_file; int alias_file_broken; int folder; int data_file; char *version; }; /**/ void Init_raliasfile() { cRAliasFile = rb_define_class("RAliasFile", rb_cObject); rb_define_method(RAliasFile, "initialize", m_raliasfile_init, 1); rb_define_method(RAliasFile, "new", m_raliasfile_new, 1); rb_define_method(RAliasFile, "set_alias_path", m_set_alias_path, 1); rb_define_method(RAliasFile, "alias_path", m_alias_path, 0); rb_define_method(RAliasFile, "orig_path", m_orig_path, 0); rb_define_method(RAliasFile, "is_alias_file", m_is_alias_file, 0); rb_define_method(RAliasFile, "is_alias_file_broken", m_is_alias_file_broken, 0); rb_define_method(RAliasFile, "is_folder", m_is_folder, 0); rb_define_method(RAliasFile, "is_data_file", m_is_data_file, 0); rb_define_method(RAliasFile, "version", m_version, 0); } VALUE m_raliasfile_init(VALUE self, VALUE _alias_path) { alias_path = _alias_path; printf("From C => alias_path : %s\n", alias_path); rb_iv_set(self, "@alias_path", alias_path); return self; } VALUE m_raliasfile_new(VALUE self, VALUE _alias_path) { rb_iv_set(self, "@alias_path", alias_path); printf("m_raliasfile_new"); alias_path = _alias_path; return self; } VALUE m_set_alias_path(VALUE self, VALUE _alias_path) { alias_path = _alias_path; rb_iv_set(self, "@alias_path", alias_path); // return rb_str_new2((char *) alias_path); } VALUE m_alias_path(VALUE self) { // char *alias_path = "/path/to/something/undefined"; return rb_str_new2((char *) alias_path); } VALUE m_orig_path(VALUE self) { char *orig_path = "/Users/yvon/work/Ruby/Native/RubyInline-3.5.0.gem"; return rb_str_new2(orig_path); } VALUE m_is_alias_file(VALUE self) { int alias_file = 1; return INT2FIX(alias_file); } VALUE m_is_alias_file_broken(VALUE self) { int alias_file_broken = 0; return INT2FIX(alias_file_broken); } VALUE m_is_folder(VALUE self) { int folder = 0; return INT2FIX(folder); } VALUE m_is_data_file(VALUE self) { int data_file = 0; return INT2FIX(data_file); } VALUE m_version(VALUE self) { char *version = "0.0.1"; return rb_str_new2(version); } ------------------------------------------------------------------------ --- raliasfile_test.rb ------------------------------------------------- #!/usr/bin/env ruby # # raliastest.rb # require 'osx/ralias/raliasfile' a=RAliasFile.new("/Users/yvon/work/Ruby/Native/C/doc/Introduction_ANSI_C _html") #From C => alias_path : a.set_alias_path("/Users/yvon/work/Ruby/Native/C/doc/Introduction_ANSI_C _html") puts a.alias_path # => puts a.orig_path # => /Users/yvon/work/Ruby/Native/RubyInline-3.5.0.gem puts a.is_alias_file # => 1 puts a.is_alias_file_broken # => 0 puts a.is_folder # => 0 puts a.is_data_file # => 0 puts a.version # => 0.0.1 ------------------------------------------------------------------------ note that, for the time being this class do nothing, just want to return the input value (alias_path). However this is the "skeleton" of what i need to do and exists allready in ObjC. -- une b�vue