>>>>> "F" == Fredrik Jagenheim <jagenheim / gmail.com> writes:

F> This is basically what I'm trying to do:

 Well, in ruby

F> -------8<------ Bitmask.c
F> #include "ruby.h"

F> static VALUE
F> bm_new(VALUE class)
F> {
F>   long* bitmask;
F>   bitmask = ALLOC(long);
F>   *bitmask = 0;
F>   VALUE data = Data_Wrap_Struct(class, 0, free, bitmask);
F>   return data; 
F> }

   bitmask = 0

F> static VALUE
F> bm_add_bit(VALUE self, VALUE bit)
F> {
F>   long* bitmask;
F>   int int_bit = NUM2INT(bit);
F>   printf("in to add_bit: %s %s\n", 
F>       RSTRING(rb_inspect(self))->ptr,
F>       RSTRING(rb_inspect(bit))->ptr);
F>   Data_Get_Struct(self, long, bitmask);
F>   *bitmask |= 1 << int_bit;
F>   return self; 
F> }

   bitmask |= 1 << bit

F> static VALUE
F> bm_add_bits(VALUE self, VALUE bits)
F> {
F>   printf("in to add_bits: %s\n", RSTRING(rb_inspect(bits))->ptr);
F>   rb_iterate(rb_each, bits, bm_add_bit, 1);
F>   return self; 
F> }

   bits.each {|b| bitmask |= 1 << b }

F> static VALUE
F> bm_value(VALUE self)
F> {
F>   long* bitmask;
F>   Data_Get_Struct(self, long, bitmask);
F>   return INT2NUM(*bitmask);
F> }

   bitmask



Guy Decoux