From: ts Date: 2003-12-10T00:29:36+09:00 Subject: Re: passing a func to a ruby func >>>>> "e" == elathan writes: e> Can I export a function such as qsort() of the Linux stdlib to a Ruby e> method. qsort() takes a C function pointer as a parameter. Not really understood what you want to do, but for qsort a stupid example svg% cat aa.c #include static int aa_sort(const void *va, const void *vb) { if (rb_block_given_p()) { return NUM2INT(rb_yield(rb_assoc_new(*(VALUE *)va, *(VALUE *)vb))); } return NUM2INT(rb_funcall(*(VALUE *)va, rb_intern("<=>"), 1, *(VALUE *)vb)); } static VALUE aa_qsort(VALUE obj, VALUE a) { a = rb_Array(a); qsort(RARRAY(a)->ptr, RARRAY(a)->len, sizeof(VALUE), aa_sort); return a; } void Init_aa() { rb_define_global_function("qsort!", aa_qsort, 1); } svg% svg% ruby -raa -e 'p qsort!([3,6,8,1,0])' [0, 1, 3, 6, 8] svg% svg% ruby -raa -e 'p qsort!([3,6,8,1,0]) {|a, b| b <=> a}' [8, 6, 3, 1, 0] svg% Guy Decoux