T_STRUCT! T_BIGNUM! T_FIXNUM! T_COMPLEX T_RATIONAL T_FILE! ! T_TRUE! ! T_FALSE T_DATA T_SYMBOL nil ordinary object class module floating point number string regular expression array associative array (Ruby) structure multi precision integer Fixnum(31bit or 63bit integer) complex number rational number IO true false data symbol CHECK THE DATA TYPE OF ‘VALUE’
numbers into C integers int NUM2INT(Numeric); int FIX2INT(Fixnum); unsigned int NUM2UINT(Numeric); unsigned int FIX2UINT(Fixnum); long NUM2LONG(Number); long FIX2LONG(Fixnum); double NUM2DBL(Numeric); // convert any Ruby strings into C char* char NUM2ULONG(Numeric_or_String); char* StringValue(str); char* StringValuePtr(str); char* StringValueCStr(str); // for other objects RSTRING_LEN(obj); // length of the Ruby string RSTRING_PTR(obj); // pointer to string storage VALUE array; RARRAY(array)->len; // length of the Ruby array RARRAY_LEN RARRAY(array)->capa; // capacity of the Ruby array RARRAY(array)->ptr; // pointer to array storage RARRAY_PTR // There are similar accessors for hashes (RHASH), files (RFILE) and so on.
to Ruby values INT2FIX(); // for integers within 31bits. INT2NUM(); // for arbitrary sized integer. int version = 100; static VALUE madridrb_version(VALUE self) { return INT2NUM(version); }
rb_ary_new4(long n, VALUE *elts); //Creates an n-element array from a C array. rb_ary_to_ary(VALUE obj); rb_ary_aref(argc, VALUE *argv, VALUE ary); rb_ary_entry(VALUE ary, long offset); // ary[offset] rb_ary_subseq(VALUE ary, long beg, long len); // ary[beg,len] rb_ary_push(VALUE ary, VALUE val); rb_ary_pop(VALUE ary); rb_ary_shift(VALUE ary); rb_ary_unshift(VALUE ary, VALUE val); rb_ary_cat(VALUE ary, const VALUE *ptr, long len);