C/Ruby data type conversion functions and macros
上一篇 /
下一篇 2007-08-23 14:24:24
/ 个人分类:Ruby
C/Ruby data type conversion functions and macros
C Data Types to Ruby Objects:
INT2NUM(int) → Fixnum or Bignum
INT2FIX(int) → Fixnum (faster)
LONG2NUM(long → Fixnum or Bignum
LONG2FIX(int) → Fixnum (faster)
LL2NUM(long long) → Fixnum or Bignum (if native
system supports long long type)
ULL2NUM(long long) → Fixnum or Bignum (if native
system supports long long type)
CHR2FIX(char) → Fixnum
rb_str_new2(char *) → String
rb_float_new(double) → Float
Ruby Objects to C Data Types:
int NUM2INT(Numeric) (Includes type check)
int FIX2INT(Fixnum) (Faster)
unsigned int NUM2UINT(Numeric) (Includes type check)
unsigned int FIX2UINT(Fixnum) (Includes type check)
long NUM2LONG(Numeric) (Includes type check)
long FIX2LONG(Fixnum) (Faster)
unsigned long NUM2ULONG(Numeric) (Includes type check)
char NUM2CHR(Numeric or String) (Includes type check)
double NUM2DBL(Numeric)
see text for strings. . .
Ruby strings, therefore, is to do what the interpreter does and use both a pointer and a
length. In fact, Ruby String objects are actually references to an RString structure,
and the RString structure contains both a length and a pointer field. You can access
the structure via the RSTRING macro.
VALUE str;
RSTRING(str)>
len ! length of the Ruby string
RSTRING(str)>
ptr ! pointer to string storage
导入论坛
收藏
分享给好友
推荐到圈子
管理
举报
TAG:
extension
ruby