On Tue, 24 Jun 2003 23:36:19 +0000, Shashank Date wrote:
> "Simon Strandgaard" <0bz63fz3m1qt3001 / sneakemail.com>
>>
>> OK.. nice to know.  I was worried that it wouldn't work on windows.
>> Perhaps you can add a short guide to rubygarden about how you have
>> setup'ed compilation on windows ?
> 
> Sure ... first let me learn how to modify the contents of rubygarden.

At the bottom there is a link, labeled 'Edit text of this page'
You can do anonymous editing, but for other wiki-fans sake I suggest that
register yourself. 

http://www.rubygarden.org/ruby?RubyApi/HowtoCompile

 
>>
>>
>> #include <ruby.h>
>> int main(int argc, char *argv[]) {
>> int n;
>> VALUE args[2];
>> VALUE klass;
>> VALUE instance;
>>
>> ruby_init();
>> args[0] = INT2FIX(4);
>> args[1] = rb_str_new2("ok");
>> n = 2;
>> klass = rb_path2class("Array");
>> instance = rb_class_new_instance(n, args, klass);
> 
> I tried replacing the above two lines by :
> 
>      klass = rb_const_get(rb_cObject, rb_intern("Array"));
>      instance = rb_funcall2(klass, rb_intern("new"), argc, argv);
> 
> but my program crashed.  Am I missing something ?

The 2nd line is 'int main(int argc, char *argv[])'.. If
you use 'argc' or 'argv' you will then be refering to these.
The reason that your program chrashed is because Ruby expects an
array of VALUEs..  you supplied 'argv' which is 'char **'.

If you look in the Ruby-source, in 'ruby.h' you can see that
VALUE simply is:   typedef unsigned long VALUE;

Try write this instead:
 
    klass = rb_const_get(rb_cObject, rb_intern("Array"));
    instance = rb_funcall2(klass, rb_intern("new"), n, args);


>> /* tell GC that there is a new instance in town. */
>> rb_gc_register_address(&instance);
>>
>> rb_p(instance);
>>
>> ruby_finalize();
>> return 0;
>> }
>>

--
Simon Strandgaard