1998-01-16 15:13:05 +03:00
|
|
|
.\" README.EXT - -*- Text -*- created at: Mon Aug 7 16:45:54 JST 1995
|
|
|
|
|
1999-08-24 12:21:56 +04:00
|
|
|
This document explains how to make extension libraries for Ruby.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
1. Basic knowledge
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
In C, variables have types and data do not have types. In contrast,
|
2002-10-23 12:20:35 +04:00
|
|
|
Ruby variables do not have a static type, and data themselves have
|
|
|
|
types, so data will need to be converted between the languages.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2006-09-13 13:49:58 +04:00
|
|
|
Data in Ruby are represented by the C type `VALUE'. Each VALUE data
|
|
|
|
has its data-type.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
To retrieve C data from a VALUE, you need to:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
(1) Identify the VALUE's data type
|
|
|
|
(2) Convert the VALUE into C data
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Converting to the wrong data type may cause serious problems.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
|
|
|
|
1.1 Data-types
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
The Ruby interpreter has the following data types:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
T_NIL nil
|
1999-08-24 12:21:56 +04:00
|
|
|
T_OBJECT ordinary object
|
1998-01-16 15:13:05 +03:00
|
|
|
T_CLASS class
|
|
|
|
T_MODULE module
|
|
|
|
T_FLOAT floating point number
|
|
|
|
T_STRING string
|
|
|
|
T_REGEXP regular expression
|
|
|
|
T_ARRAY array
|
|
|
|
T_FIXNUM Fixnum(31bit integer)
|
1999-08-24 12:21:56 +04:00
|
|
|
T_HASH associative array
|
1999-01-20 07:59:39 +03:00
|
|
|
T_STRUCT (Ruby) structure
|
1998-01-16 15:13:05 +03:00
|
|
|
T_BIGNUM multi precision integer
|
2003-03-20 09:27:22 +03:00
|
|
|
T_FILE IO
|
1998-01-16 15:13:05 +03:00
|
|
|
T_TRUE true
|
|
|
|
T_FALSE false
|
|
|
|
T_DATA data
|
2000-10-05 13:57:04 +04:00
|
|
|
T_SYMBOL symbol
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
In addition, there are several other types used internally:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
T_ICLASS
|
|
|
|
T_MATCH
|
2000-10-05 13:57:04 +04:00
|
|
|
T_UNDEF
|
1998-01-16 15:13:05 +03:00
|
|
|
T_VARMAP
|
|
|
|
T_SCOPE
|
|
|
|
T_NODE
|
|
|
|
|
|
|
|
Most of the types are represented by C structures.
|
|
|
|
|
|
|
|
1.2 Check Data Type of the VALUE
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
The macro TYPE() defined in ruby.h shows the data type of the VALUE.
|
1998-01-16 15:13:05 +03:00
|
|
|
TYPE() returns the constant number T_XXXX described above. To handle
|
2002-10-23 12:20:35 +04:00
|
|
|
data types, your code will look something like this:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
switch (TYPE(obj)) {
|
|
|
|
case T_FIXNUM:
|
|
|
|
/* process Fixnum */
|
|
|
|
break;
|
|
|
|
case T_STRING:
|
|
|
|
/* process String */
|
|
|
|
break;
|
|
|
|
case T_ARRAY:
|
|
|
|
/* process Array */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* raise exception */
|
2000-03-06 07:15:42 +03:00
|
|
|
rb_raise(rb_eTypeError, "not valid value");
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
There is the data-type check function
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
void Check_Type(VALUE value, int type)
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
which raises an exception if the VALUE does not have the type specified.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
There are also faster check macros for fixnums and nil.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
FIXNUM_P(obj)
|
|
|
|
NIL_P(obj)
|
|
|
|
|
|
|
|
1.3 Convert VALUE into C data
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
The data for type T_NIL, T_FALSE, T_TRUE are nil, true, false
|
|
|
|
respectively. They are singletons for the data type.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
The T_FIXNUM data is a 31bit length fixed integer (63bit length on
|
2006-09-13 13:49:58 +04:00
|
|
|
some machines), which can be converted to a C integer by using the
|
2002-10-23 12:20:35 +04:00
|
|
|
FIX2INT() macro. There is also NUM2INT() which converts any Ruby
|
|
|
|
numbers into C integers. The NUM2INT() macro includes a type check, so
|
2003-03-26 10:01:14 +03:00
|
|
|
an exception will be raised if the conversion failed. NUM2DBL() can
|
2006-09-13 13:49:58 +04:00
|
|
|
be used to retrieve the double float value in the same way.
|
2003-03-26 10:01:14 +03:00
|
|
|
|
2006-09-13 13:49:58 +04:00
|
|
|
In version 1.7 or later it is recommended that you use the new macros
|
2006-09-13 18:45:21 +04:00
|
|
|
StringValue() and StringValuePtr() to get a char* from a VALUE.
|
|
|
|
StringValue(var) replaces var's value with the result of "var.to_str()".
|
|
|
|
StringValuePtr(var) does same replacement and returns char*
|
|
|
|
representation of var. These macros will skip the replacement if var is
|
|
|
|
a String. Notice that the macros take only the lvalue as their
|
|
|
|
argument, to change the value of var in place.
|
2003-03-26 10:01:14 +03:00
|
|
|
|
2006-09-13 13:49:58 +04:00
|
|
|
In version 1.6 or earlier, STR2CSTR() was used to do the same thing
|
|
|
|
but now it is deprecated in version 1.7, because STR2CSTR() has a risk
|
|
|
|
of a dangling pointer problem in the to_str() impliclit conversion.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
Other data types have corresponding C structures, e.g. struct RArray
|
2006-09-13 13:49:58 +04:00
|
|
|
for T_ARRAY etc. The VALUE of the type which has the corresponding structure
|
1999-01-20 07:59:39 +03:00
|
|
|
can be cast to retrieve the pointer to the struct. The casting macro
|
2002-10-23 12:20:35 +04:00
|
|
|
will be of the form RXXXX for each data type; for instance, RARRAY(obj).
|
|
|
|
See "ruby.h".
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2006-09-16 14:51:35 +04:00
|
|
|
There are some accessing macros for structure members, for example
|
|
|
|
`RSTRING_LEN(s)' to to get the size of the Ruby String object. The
|
|
|
|
allocated region can be accessed by `RSTRING_PTR(str). For arrays, use
|
|
|
|
`RARRAY_LEN(ary) and `RARRAY_PTR(ary) respectively.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
Notice: Do not change the value of the structure directly, unless you
|
2002-10-23 12:20:35 +04:00
|
|
|
are responsible for the result. This ends up being the cause of interesting
|
1999-01-20 07:59:39 +03:00
|
|
|
bugs.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
1.4 Convert C data into VALUE
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
To convert C data to Ruby values:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
* FIXNUM
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
left shift 1 bit, and turn on LSB.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
* Other pointer values
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
cast to VALUE.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
You can determine whether a VALUE is pointer or not by checking its LSB.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Notice Ruby does not allow arbitrary pointer values to be a VALUE. They
|
|
|
|
should be pointers to the structures which Ruby knows about. The known
|
1999-08-13 09:45:20 +04:00
|
|
|
structures are defined in <ruby.h>.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
To convert C numbers to Ruby values, use these macros.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-24 12:21:56 +04:00
|
|
|
INT2FIX() for integers within 31bits.
|
1999-08-13 09:45:20 +04:00
|
|
|
INT2NUM() for arbitrary sized integer.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
INT2NUM() converts an integer into a Bignum if it is out of the FIXNUM
|
|
|
|
range, but is a bit slower.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
1.5 Manipulating Ruby data
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
As I already mentioned, it is not recommended to modify an object's internal
|
|
|
|
structure. To manipulate objects, use the functions supplied by the Ruby
|
|
|
|
interpreter. Some (not all) of the useful functions are listed below:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-24 12:21:56 +04:00
|
|
|
String functions
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
rb_str_new(const char *ptr, long len)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
Creates a new Ruby string.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
rb_str_new2(const char *ptr)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Creates a new Ruby string from a C string. This is equivalent to
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_str_new(ptr, strlen(ptr)).
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
rb_tainted_str_new(const char *ptr, long len)
|
2000-07-10 08:49:24 +04:00
|
|
|
|
|
|
|
Creates a new tainted Ruby string. Strings from external data
|
2002-10-23 12:20:35 +04:00
|
|
|
sources should be tainted.
|
2000-07-10 08:49:24 +04:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
rb_tainted_str_new2(const char *ptr)
|
2000-07-10 08:49:24 +04:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Creates a new tainted Ruby string from a C string.
|
2000-07-10 08:49:24 +04:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
rb_str_cat(VALUE str, const char *ptr, long len)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Appends len bytes of data from ptr to the Ruby string.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
Array functions
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_ary_new()
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Creates an array with no elements.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
rb_ary_new2(long len)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Creates an array with no elements, allocating internal buffer
|
1998-01-16 15:13:05 +03:00
|
|
|
for len elements.
|
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
rb_ary_new3(long n, ...)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Creates an n-element array from the arguments.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
rb_ary_new4(long n, VALUE *elts)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Creates an n-element array from a C array.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_ary_push(VALUE ary, VALUE val)
|
|
|
|
rb_ary_pop(VALUE ary)
|
|
|
|
rb_ary_shift(VALUE ary)
|
|
|
|
rb_ary_unshift(VALUE ary, VALUE val)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
Array operations. The first argument to each functions must be an
|
2006-09-13 13:49:58 +04:00
|
|
|
array. They may dump core if other types are given.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
2. Extending Ruby with C
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
2.1 Addding new features to Ruby
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
You can add new features (classes, methods, etc.) to the Ruby
|
2002-10-23 12:20:35 +04:00
|
|
|
interpreter. Ruby provides APIs for defining the following things:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
* Classes, Modules
|
|
|
|
* Methods, Singleton Methods
|
|
|
|
* Constants
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
2.1.1 Class/module definition
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
To define a class or module, use the functions below:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
VALUE rb_define_class(const char *name, VALUE super)
|
|
|
|
VALUE rb_define_module(const char *name)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-24 12:21:56 +04:00
|
|
|
These functions return the newly created class or module. You may
|
2002-10-23 12:20:35 +04:00
|
|
|
want to save this reference into a variable to use later.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
To define nested classes or modules, use the functions below:
|
2000-03-06 07:15:42 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
|
|
|
|
VALUE rb_define_module_under(VALUE outer, const char *name)
|
2000-03-06 07:15:42 +03:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
2.1.2 Method/singleton method definition
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
To define methods or singleton methods, use these functions:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
void rb_define_method(VALUE klass, const char *name,
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE (*func)(), int argc)
|
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
void rb_define_singleton_method(VALUE object, const char *name,
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE (*func)(), int argc)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
The `argc' represents the number of the arguments to the C function,
|
2006-09-13 13:49:58 +04:00
|
|
|
which must be less than 17. But I doubt you'll need that many.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
If `argc' is negative, it specifies the calling sequence, not number of
|
1999-01-20 07:59:39 +03:00
|
|
|
the arguments.
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
If argc is -1, the function will be called as:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE func(int argc, VALUE *argv, VALUE obj)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
where argc is the actual number of arguments, argv is the C array of
|
|
|
|
the arguments, and obj is the receiver.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
If argc is -2, the arguments are passed in a Ruby array. The function
|
1999-01-20 07:59:39 +03:00
|
|
|
will be called like:
|
|
|
|
|
|
|
|
VALUE func(VALUE obj, VALUE args)
|
|
|
|
|
|
|
|
where obj is the receiver, and args is the Ruby array containing
|
|
|
|
actual arguments.
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
There are two more functions to define methods. One is to define
|
|
|
|
private methods:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
void rb_define_private_method(VALUE klass, const char *name,
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE (*func)(), int argc)
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
The other is to define module functions, which are private AND singleton
|
|
|
|
methods of the module. For example, sqrt is the module function
|
2006-09-13 13:49:58 +04:00
|
|
|
defined in Math module. It can be called in the following way:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
Math.sqrt(4)
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
or
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
include Math
|
|
|
|
sqrt(4)
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
To define module functions, use:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
void rb_define_module_function(VALUE module, const char *name,
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE (*func)(), int argc)
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Oh, in addition, function-like methods, which are private methods defined
|
|
|
|
in the Kernel module, can be defined using:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
void rb_define_global_function(const char *name, VALUE (*func)(), int argc)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2006-09-13 13:49:58 +04:00
|
|
|
To define an alias for the method,
|
2000-07-10 08:49:24 +04:00
|
|
|
|
|
|
|
void rb_define_alias(VALUE module, const char* new, const char* old);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2005-09-21 03:20:58 +04:00
|
|
|
To define and undefine the `allocate' class method,
|
|
|
|
|
|
|
|
void rb_define_alloc_func(VALUE klass, VALUE (*func)(VALUE klass));
|
|
|
|
void rb_undef_alloc_func(VALUE klass);
|
|
|
|
|
|
|
|
func have to take the klass as the argument and return a newly
|
|
|
|
allocated instance. This instance should be empty as possible,
|
|
|
|
without any expensive (including external) resources.
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
2.1.3 Constant definition
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
We have 2 functions to define constants:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
void rb_define_const(VALUE klass, const char *name, VALUE val)
|
|
|
|
void rb_define_global_const(const char *name, VALUE val)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
The former is to define a constant under specified class/module. The
|
|
|
|
latter is to define a global constant.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
2.2 Use Ruby features from C
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
There are several ways to invoke Ruby's features from C code.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
2.2.1 Evaluate Ruby Programs in a String
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
The easiest way to use Ruby's functionality from a C program is to
|
2006-09-13 13:49:58 +04:00
|
|
|
evaluate the string as Ruby program. This function will do the job:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
VALUE rb_eval_string(const char *str)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Evaluation is done under the current context, thus current local variables
|
1999-01-20 07:59:39 +03:00
|
|
|
of the innermost method (which is defined by Ruby) can be accessed.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
2.2.2 ID or Symbol
|
|
|
|
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-10 01:20:17 +04:00
|
|
|
You can invoke methods directly, without parsing the string. First I need
|
|
|
|
to explain about ID. ID is the integer number to represent Ruby's
|
|
|
|
identifiers such as variable names. The Ruby data type corresponding to ID
|
|
|
|
is Symbol. It can be accessed from Ruby in the form:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
:Identifier
|
1998-01-16 15:13:05 +03:00
|
|
|
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-10 01:20:17 +04:00
|
|
|
You can get the ID value from a string within C code by using
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
rb_intern(const char *name)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-10 01:20:17 +04:00
|
|
|
You can retrieve ID from Ruby object (Symbol or String) given as an
|
|
|
|
argument by using
|
|
|
|
|
|
|
|
rb_to_id(VALUE symbol)
|
|
|
|
|
|
|
|
You can convert C ID to Ruby Symbol by using
|
|
|
|
|
|
|
|
VALUE ID2SYM(ID id)
|
|
|
|
|
|
|
|
and to convert Ruby Symbol object to ID, use
|
|
|
|
|
|
|
|
ID SYM2ID(VALUE symbol)
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
2.2.3 Invoke Ruby method from C
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
To invoke methods directly, you can use the function below
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
VALUE rb_funcall(VALUE recv, ID mid, int argc, ...)
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
This function invokes a method on the recv, with the method name
|
|
|
|
specified by the symbol mid.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
2.2.4 Accessing the variables and constants
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
You can access class variables and instance variables using access
|
|
|
|
functions. Also, global variables can be shared between both environments.
|
1999-08-13 09:45:20 +04:00
|
|
|
There's no way to access Ruby's local variables.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
The functions to access/modify instance variables are below:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
VALUE rb_ivar_get(VALUE obj, ID id)
|
|
|
|
VALUE rb_ivar_set(VALUE obj, ID id, VALUE val)
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
id must be the symbol, which can be retrieved by rb_intern().
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
To access the constants of the class/module:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
VALUE rb_const_get(VALUE obj, ID id)
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
See 2.1.3 for defining new constant.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-24 12:21:56 +04:00
|
|
|
3. Information sharing between Ruby and C
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
3.1 Ruby constants that C can be accessed from C
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
The following Ruby constants can be referred from C.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
Qtrue
|
|
|
|
Qfalse
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Boolean values. Qfalse is false in C also (i.e. 0).
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
Qnil
|
|
|
|
|
|
|
|
Ruby nil in C scope.
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
3.2 Global variables shared between C and Ruby
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Information can be shared between the two environments using shared global
|
1999-08-13 09:45:20 +04:00
|
|
|
variables. To define them, you can use functions listed below:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
void rb_define_variable(const char *name, VALUE *var)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
This function defines the variable which is shared by both environments.
|
|
|
|
The value of the global variable pointed to by `var' can be accessed
|
1999-08-13 09:45:20 +04:00
|
|
|
through Ruby's global variable named `name'.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
You can define read-only (from Ruby, of course) variables using the
|
1999-08-13 09:45:20 +04:00
|
|
|
function below.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
void rb_define_readonly_variable(const char *name, VALUE *var)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
You can defined hooked variables. The accessor functions (getter and
|
|
|
|
setter) are called on access to the hooked variables.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
void rb_define_hooked_variable(constchar *name, VALUE *var,
|
|
|
|
VALUE (*getter)(), void (*setter)())
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
If you need to supply either setter or getter, just supply 0 for the
|
|
|
|
hook you don't need. If both hooks are 0, rb_define_hooked_variable()
|
|
|
|
works just like rb_define_variable().
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
void rb_define_virtual_variable(const char *name,
|
|
|
|
VALUE (*getter)(), void (*setter)())
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
This function defines a Ruby global variable without a corresponding C
|
1999-08-13 09:45:20 +04:00
|
|
|
variable. The value of the variable will be set/get only by hooks.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
The prototypes of the getter and setter functions are as follows:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
(*getter)(ID id, void *data, struct global_entry* entry);
|
|
|
|
(*setter)(VALUE val, ID id, void *data, struct global_entry* entry);
|
|
|
|
|
2006-09-13 13:49:58 +04:00
|
|
|
3.3 Encapsulate C data into a Ruby object
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
To wrap and objectify a C pointer as a Ruby object (so called
|
1999-08-13 09:45:20 +04:00
|
|
|
DATA), use Data_Wrap_Struct().
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-03-06 07:15:42 +03:00
|
|
|
Data_Wrap_Struct(klass, mark, free, ptr)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-03-06 07:15:42 +03:00
|
|
|
Data_Wrap_Struct() returns a created DATA object. The klass argument
|
1999-08-13 09:45:20 +04:00
|
|
|
is the class for the DATA object. The mark argument is the function
|
|
|
|
to mark Ruby objects pointed by this data. The free argument is the
|
2003-04-02 10:11:28 +04:00
|
|
|
function to free the pointer allocation. If this is -1, the pointer
|
|
|
|
will be just freed. The functions mark and free will be called from
|
|
|
|
garbage collector.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
You can allocate and wrap the structure in one step.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-24 12:21:56 +04:00
|
|
|
Data_Make_Struct(klass, type, mark, free, sval)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
This macro returns an allocated Data object, wrapping the pointer to
|
|
|
|
the structure, which is also allocated. This macro works like:
|
|
|
|
|
1999-08-24 12:21:56 +04:00
|
|
|
(sval = ALLOC(type), Data_Wrap_Struct(klass, mark, free, sval))
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Arguments klass, mark, and free work like their counterparts in
|
|
|
|
Data_Wrap_Struct(). A pointer to the allocated structure will be
|
|
|
|
assigned to sval, which should be a pointer of the type specified.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
To retrieve the C pointer from the Data object, use the macro
|
|
|
|
Data_Get_Struct().
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
Data_Get_Struct(obj, type, sval)
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
A pointer to the structure will be assigned to the variable sval.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
See the example below for details.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
4. Example - Creating dbm extension
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
OK, here's the example of making an extension library. This is the
|
|
|
|
extension to access DBMs. The full source is included in the ext/
|
1999-08-13 09:45:20 +04:00
|
|
|
directory in the Ruby's source tree.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
(1) make the directory
|
|
|
|
|
|
|
|
% mkdir ext/dbm
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
Make a directory for the extension library under ext directory.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2004-11-01 13:41:08 +03:00
|
|
|
(2) design the library
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
You need to design the library features, before making it.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2004-11-01 13:41:08 +03:00
|
|
|
(3) write C code.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
You need to write C code for your extension library. If your library
|
|
|
|
has only one source file, choosing ``LIBRARY.c'' as a file name is
|
2002-10-23 12:20:35 +04:00
|
|
|
preferred. On the other hand, in case your library has multiple source
|
1999-08-24 12:21:56 +04:00
|
|
|
files, avoid choosing ``LIBRARY.c'' for a file name. It may conflict
|
2002-10-23 12:20:35 +04:00
|
|
|
with an intermediate file ``LIBRARY.o'' on some platforms.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
Ruby will execute the initializing function named ``Init_LIBRARY'' in
|
1999-08-24 12:21:56 +04:00
|
|
|
the library. For example, ``Init_dbm()'' will be executed when loading
|
1999-08-13 09:45:20 +04:00
|
|
|
the library.
|
|
|
|
|
|
|
|
Here's the example of an initializing function.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
--
|
|
|
|
Init_dbm()
|
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
/* define DBM class */
|
|
|
|
cDBM = rb_define_class("DBM", rb_cObject);
|
|
|
|
/* DBM includes Enumerate module */
|
|
|
|
rb_include_module(cDBM, rb_mEnumerable);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
/* DBM has class method open(): arguments are received as C array */
|
1998-01-16 15:13:05 +03:00
|
|
|
rb_define_singleton_method(cDBM, "open", fdbm_s_open, -1);
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
/* DBM instance method close(): no args */
|
1998-01-16 15:13:05 +03:00
|
|
|
rb_define_method(cDBM, "close", fdbm_close, 0);
|
1999-01-20 07:59:39 +03:00
|
|
|
/* DBM instance method []: 1 argument */
|
1998-01-16 15:13:05 +03:00
|
|
|
rb_define_method(cDBM, "[]", fdbm_fetch, 1);
|
|
|
|
:
|
|
|
|
|
2003-03-20 09:27:22 +03:00
|
|
|
/* ID for a instance variable to store DBM data */
|
|
|
|
id_dbm = rb_intern("dbm");
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
--
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
The dbm extension wraps the dbm struct in the C environment using
|
|
|
|
Data_Make_Struct.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
--
|
|
|
|
struct dbmdata {
|
|
|
|
int di_size;
|
|
|
|
DBM *di_dbm;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-03-06 07:15:42 +03:00
|
|
|
obj = Data_Make_Struct(klass, struct dbmdata, 0, free_dbm, dbmp);
|
1998-01-16 15:13:05 +03:00
|
|
|
--
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
This code wraps the dbmdata structure into a Ruby object. We avoid wrapping
|
1999-08-13 09:45:20 +04:00
|
|
|
DBM* directly, because we want to cache size information.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
To retrieve the dbmdata structure from a Ruby object, we define the
|
|
|
|
following macro:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
--
|
|
|
|
#define GetDBM(obj, dbmp) {\
|
|
|
|
Data_Get_Struct(obj, struct dbmdata, dbmp);\
|
|
|
|
if (dbmp->di_dbm == 0) closed_dbm();\
|
|
|
|
}
|
|
|
|
--
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
This sort of complicated macro does the retrieving and close checking for
|
1999-08-13 09:45:20 +04:00
|
|
|
the DBM.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
There are three kinds of way to receive method arguments. First,
|
|
|
|
methods with a fixed number of arguments receive arguments like this:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
--
|
|
|
|
static VALUE
|
|
|
|
fdbm_delete(obj, keystr)
|
|
|
|
VALUE obj, keystr;
|
|
|
|
{
|
|
|
|
:
|
|
|
|
}
|
|
|
|
--
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
The first argument of the C function is the self, the rest are the
|
|
|
|
arguments to the method.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Second, methods with an arbitrary number of arguments receive
|
1999-08-13 09:45:20 +04:00
|
|
|
arguments like this:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
--
|
|
|
|
static VALUE
|
1999-08-24 12:21:56 +04:00
|
|
|
fdbm_s_open(argc, argv, klass)
|
1998-01-16 15:13:05 +03:00
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
1999-08-24 12:21:56 +04:00
|
|
|
VALUE klass;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
:
|
|
|
|
if (rb_scan_args(argc, argv, "11", &file, &vmode) == 1) {
|
|
|
|
mode = 0666; /* default value */
|
|
|
|
}
|
|
|
|
:
|
|
|
|
}
|
|
|
|
--
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
The first argument is the number of method arguments, the second
|
|
|
|
argument is the C array of the method arguments, and the third
|
1999-08-13 09:45:20 +04:00
|
|
|
argument is the receiver of the method.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
You can use the function rb_scan_args() to check and retrieve the
|
2002-10-23 12:20:35 +04:00
|
|
|
arguments. For example, "11" means that the method requires at least one
|
1999-08-13 09:45:20 +04:00
|
|
|
argument, and at most receives two arguments.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Methods with an arbitrary number of arguments can receive arguments
|
1999-08-13 09:45:20 +04:00
|
|
|
by Ruby's array, like this:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
--
|
|
|
|
static VALUE
|
|
|
|
fdbm_indexes(obj, args)
|
1999-08-13 09:45:20 +04:00
|
|
|
VALUE obj, args;
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
:
|
|
|
|
}
|
|
|
|
--
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
The first argument is the receiver, the second one is the Ruby array
|
|
|
|
which contains the arguments to the method.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
** Notice
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
GC should know about global variables which refer to Ruby's objects, but
|
|
|
|
are not exported to the Ruby world. You need to protect them by
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
void rb_global_variable(VALUE *var)
|
|
|
|
|
2004-11-01 13:41:08 +03:00
|
|
|
(4) prepare extconf.rb
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
If the file named extconf.rb exists, it will be executed to generate
|
2004-11-10 06:31:55 +03:00
|
|
|
Makefile.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2006-09-13 13:49:58 +04:00
|
|
|
extconf.rb is the file for checking compilation conditions etc. You
|
1999-08-13 09:45:20 +04:00
|
|
|
need to put
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
require 'mkmf'
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
at the top of the file. You can use the functions below to check
|
|
|
|
various conditions.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
have_library(lib, func): check whether library containing function exists.
|
2000-07-07 07:20:53 +04:00
|
|
|
have_func(func, header): check whether function exists
|
1999-08-13 09:45:20 +04:00
|
|
|
have_header(header): check whether header file exists
|
|
|
|
create_makefile(target): generate Makefile
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
The value of the variables below will affect the Makefile.
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2005-09-21 03:20:58 +04:00
|
|
|
$CFLAGS: included in CFLAGS make variable (such as -O)
|
|
|
|
$CPPFLAGS: included in CPPFLAGS make variable (such as -I, -D)
|
1999-08-13 09:45:20 +04:00
|
|
|
$LDFLAGS: included in LDFLAGS make variable (such as -L)
|
2005-09-21 03:20:58 +04:00
|
|
|
$objs: list of object file names
|
|
|
|
|
2006-09-13 13:49:58 +04:00
|
|
|
Normally, the object files list is automatically generated by searching
|
|
|
|
source files, but you must define them explicitly if any sources will
|
2005-09-21 03:20:58 +04:00
|
|
|
be generated while building.
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
If a compilation condition is not fulfilled, you should not call
|
2006-09-13 13:49:58 +04:00
|
|
|
``create_makefile''. The Makefile will not be generated, compilation will
|
1999-08-13 09:45:20 +04:00
|
|
|
not be done.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2004-11-01 13:41:08 +03:00
|
|
|
(5) prepare depend (optional)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
If the file named depend exists, Makefile will include that file to
|
2002-10-23 12:20:35 +04:00
|
|
|
check dependencies. You can make this file by invoking
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-03-06 07:15:42 +03:00
|
|
|
% gcc -MM *.c > depend
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2006-09-13 13:49:58 +04:00
|
|
|
It's harmless. Prepare it.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2004-11-01 13:41:08 +03:00
|
|
|
(6) generate Makefile
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Try generating the Makefile by:
|
1999-08-13 09:45:20 +04:00
|
|
|
|
|
|
|
ruby extconf.rb
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
You don't need this step if you put the extension library under the ext
|
1999-08-13 09:45:20 +04:00
|
|
|
directory of the ruby source tree. In that case, compilation of the
|
|
|
|
interpreter will do this step for you.
|
|
|
|
|
2004-11-01 13:41:08 +03:00
|
|
|
(7) make
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
Type
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
make
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
to compile your extension. You don't need this step either if you have
|
2006-09-13 13:49:58 +04:00
|
|
|
put the extension library under the ext directory of the ruby source tree.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2004-11-01 13:41:08 +03:00
|
|
|
(8) debug
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
You may need to rb_debug the extension. Extensions can be linked
|
2006-09-13 13:49:58 +04:00
|
|
|
statically by adding the directory name in the ext/Setup file so that
|
2002-10-23 12:20:35 +04:00
|
|
|
you can inspect the extension with the debugger.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2004-11-01 13:41:08 +03:00
|
|
|
(9) done, now you have the extension library
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
You can do anything you want with your library. The author of Ruby
|
2002-10-23 12:20:35 +04:00
|
|
|
will not claim any restrictions on your code depending on the Ruby API.
|
1999-08-13 09:45:20 +04:00
|
|
|
Feel free to use, modify, distribute or sell your program.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
Appendix A. Ruby source files overview
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
ruby language core
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
class.c
|
|
|
|
error.c
|
|
|
|
eval.c
|
|
|
|
gc.c
|
|
|
|
object.c
|
|
|
|
parse.y
|
|
|
|
variable.c
|
|
|
|
|
|
|
|
utility functions
|
|
|
|
|
|
|
|
dln.c
|
|
|
|
regex.c
|
|
|
|
st.c
|
|
|
|
util.c
|
|
|
|
|
|
|
|
ruby interpreter implementation
|
|
|
|
|
|
|
|
dmyext.c
|
|
|
|
inits.c
|
|
|
|
main.c
|
|
|
|
ruby.c
|
|
|
|
version.c
|
|
|
|
|
|
|
|
class library
|
|
|
|
|
|
|
|
array.c
|
|
|
|
bignum.c
|
|
|
|
compar.c
|
|
|
|
dir.c
|
|
|
|
enum.c
|
|
|
|
file.c
|
|
|
|
hash.c
|
|
|
|
io.c
|
2000-03-06 07:15:42 +03:00
|
|
|
marshal.c
|
1998-01-16 15:13:05 +03:00
|
|
|
math.c
|
|
|
|
numeric.c
|
|
|
|
pack.c
|
2000-03-06 07:15:42 +03:00
|
|
|
prec.c
|
1998-01-16 15:13:05 +03:00
|
|
|
process.c
|
|
|
|
random.c
|
|
|
|
range.c
|
|
|
|
re.c
|
|
|
|
signal.c
|
|
|
|
sprintf.c
|
|
|
|
string.c
|
|
|
|
struct.c
|
|
|
|
time.c
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
Appendix B. Ruby extension API reference
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
** Types
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
VALUE
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
The type for the Ruby object. Actual structures are defined in ruby.h,
|
1999-08-13 09:45:20 +04:00
|
|
|
such as struct RString, etc. To refer the values in structures, use
|
|
|
|
casting macros like RSTRING(obj).
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
** Variables and constants
|
|
|
|
|
|
|
|
Qnil
|
|
|
|
|
|
|
|
const: nil object
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
Qtrue
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
const: true object(default true value)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
Qfalse
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
const: false object
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
** C pointer wrapping
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-24 12:21:56 +04:00
|
|
|
Data_Wrap_Struct(VALUE klass, void (*mark)(), void (*free)(), void *sval)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Wrap a C pointer into a Ruby object. If object has references to other
|
|
|
|
Ruby objects, they should be marked by using the mark function during
|
|
|
|
the GC process. Otherwise, mark should be 0. When this object is no
|
|
|
|
longer referred by anywhere, the pointer will be discarded by free
|
|
|
|
function.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-24 12:21:56 +04:00
|
|
|
Data_Make_Struct(klass, type, mark, free, sval)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
This macro allocates memory using malloc(), assigns it to the variable
|
|
|
|
sval, and returns the DATA encapsulating the pointer to memory region.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
Data_Get_Struct(data, type, sval)
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
This macro retrieves the pointer value from DATA, and assigns it to
|
|
|
|
the variable sval.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2003-03-20 09:27:22 +03:00
|
|
|
** Checking data types
|
|
|
|
|
|
|
|
TYPE(value)
|
|
|
|
FIXNUM_P(value)
|
|
|
|
NIL_P(value)
|
|
|
|
void Check_Type(VALUE value, int type)
|
|
|
|
void Check_SafeStr(VALUE value)
|
|
|
|
|
|
|
|
** Data type conversion
|
|
|
|
|
|
|
|
FIX2INT(value)
|
|
|
|
INT2FIX(i)
|
|
|
|
NUM2INT(value)
|
|
|
|
INT2NUM(i)
|
|
|
|
NUM2DBL(value)
|
|
|
|
rb_float_new(f)
|
2005-09-21 03:20:58 +04:00
|
|
|
StringValue(value)
|
|
|
|
StringValuePtr(value)
|
|
|
|
StringValueCStr(value)
|
2003-03-20 09:27:22 +03:00
|
|
|
rb_str_new2(s)
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
** defining class/module
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
VALUE rb_define_class(const char *name, VALUE super)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Defines a new Ruby class as a subclass of super.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
VALUE rb_define_class_under(VALUE module, const char *name, VALUE super)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Creates a new Ruby class as a subclass of super, under the module's
|
1999-08-13 09:45:20 +04:00
|
|
|
namespace.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
VALUE rb_define_module(const char *name)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Defines a new Ruby module.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2004-04-26 18:56:58 +04:00
|
|
|
VALUE rb_define_module_under(VALUE module, const char *name)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Defines a new Ruby module under the module's namespace.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-24 12:21:56 +04:00
|
|
|
void rb_include_module(VALUE klass, VALUE module)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
Includes module into class. If class already includes it, just
|
2002-10-23 12:20:35 +04:00
|
|
|
ignored.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
void rb_extend_object(VALUE object, VALUE module)
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Extend the object with the module's attributes.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
** Defining Global Variables
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
void rb_define_variable(const char *name, VALUE *var)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
Defines a global variable which is shared between C and Ruby. If name
|
2002-10-23 12:20:35 +04:00
|
|
|
contains a character which is not allowed to be part of the symbol,
|
1999-01-20 07:59:39 +03:00
|
|
|
it can't be seen from Ruby programs.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
void rb_define_readonly_variable(const char *name, VALUE *var)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
Defines a read-only global variable. Works just like
|
2006-09-13 13:49:58 +04:00
|
|
|
rb_define_variable(), except the defined variable is read-only.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
void rb_define_virtual_variable(const char *name,
|
2000-03-06 07:15:42 +03:00
|
|
|
VALUE (*getter)(), VALUE (*setter)())
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Defines a virtual variable, whose behavior is defined by a pair of C
|
1999-01-20 07:59:39 +03:00
|
|
|
functions. The getter function is called when the variable is
|
2006-09-13 13:49:58 +04:00
|
|
|
referenced. The setter function is called when the variable is set to a
|
|
|
|
value. The prototype for getter/setter functions are:
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
VALUE getter(ID id)
|
|
|
|
void setter(VALUE val, ID id)
|
|
|
|
|
|
|
|
The getter function must return the value for the access.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
void rb_define_hooked_variable(const char *name, VALUE *var,
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE (*getter)(), VALUE (*setter)())
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Defines hooked variable. It's a virtual variable with a C variable.
|
|
|
|
The getter is called as
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
VALUE getter(ID id, VALUE *var)
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
returning a new value. The setter is called as
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
void setter(VALUE val, ID id, VALUE *var)
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
GC requires C global variables which hold Ruby values to be marked.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
void rb_global_variable(VALUE *var)
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
Tells GC to protect these variables.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
** Constant Definition
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
void rb_define_const(VALUE klass, const char *name, VALUE val)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
Defines a new constant under the class/module.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
void rb_define_global_const(const char *name, VALUE val)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Defines a global constant. This is just the same as
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
rb_define_const(cKernal, name, val)
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
** Method Definition
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
rb_define_method(VALUE klass, const char *name, VALUE (*func)(), int argc)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
Defines a method for the class. func is the function pointer. argc
|
|
|
|
is the number of arguments. if argc is -1, the function will receive
|
2002-10-23 12:20:35 +04:00
|
|
|
3 arguments: argc, argv, and self. if argc is -2, the function will
|
|
|
|
receive 2 arguments, self and args, where args is a Ruby array of
|
1999-08-13 09:45:20 +04:00
|
|
|
the method arguments.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
rb_define_private_method(VALUE klass, const char *name, VALUE (*func)(), int argc)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
Defines a private method for the class. Arguments are same as
|
|
|
|
rb_define_method().
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
rb_define_singleton_method(VALUE klass, const char *name, VALUE (*func)(), int argc)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
Defines a singleton method. Arguments are same as rb_define_method().
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
rb_scan_args(int argc, VALUE *argv, const char *fmt, ...)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
Retrieve argument from argc, argv. The fmt is the format string for
|
1999-08-24 12:21:56 +04:00
|
|
|
the arguments, such as "12" for 1 non-optional argument, 2 optional
|
|
|
|
arguments. If `*' appears at the end of fmt, it means the rest of
|
2002-10-23 12:20:35 +04:00
|
|
|
the arguments are assigned to the corresponding variable, packed in
|
|
|
|
an array.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
** Invoking Ruby method
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
VALUE rb_funcall(VALUE recv, ID mid, int narg, ...)
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Invokes a method. To retrieve mid from a method name, use rb_intern().
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
VALUE rb_funcall2(VALUE recv, ID mid, int argc, VALUE *argv)
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Invokes a method, passing arguments by an array of values.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
VALUE rb_eval_string(const char *str)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Compiles and executes the string as a Ruby program.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
ID rb_intern(const char *name)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Returns ID corresponding to the name.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
char *rb_id2name(ID id)
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
Returns the name corresponding ID.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-24 12:21:56 +04:00
|
|
|
char *rb_class2name(VALUE klass)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
Returns the name of the class.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-03-06 07:15:42 +03:00
|
|
|
int rb_respond_to(VALUE object, ID id)
|
1999-10-12 08:53:36 +04:00
|
|
|
|
2000-05-01 13:42:38 +04:00
|
|
|
Returns true if the object responds to the message specified by id.
|
1999-10-12 08:53:36 +04:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
** Instance Variables
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
VALUE rb_iv_get(VALUE obj, const char *name)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
Retrieve the value of the instance variable. If the name is not
|
|
|
|
prefixed by `@', that variable shall be inaccessible from Ruby.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
VALUE rb_iv_set(VALUE obj, const char *name, VALUE val)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
Sets the value of the instance variable.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
** Control Structure
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
VALUE rb_iterate(VALUE (*func1)(), void *arg1, VALUE (*func2)(), void *arg2)
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
Calls the function func1, supplying func2 as the block. func1 will be
|
|
|
|
called with the argument arg1. func2 receives the value from yield as
|
|
|
|
the first argument, arg2 as the second argument.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
VALUE rb_yield(VALUE val)
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
Evaluates the block with value val.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
VALUE rb_rescue(VALUE (*func1)(), void *arg1, VALUE (*func2)(), void *arg2)
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Calls the function func1, with arg1 as the argument. If an exception
|
1999-08-13 09:45:20 +04:00
|
|
|
occurs during func1, it calls func2 with arg2 as the argument. The
|
|
|
|
return value of rb_rescue() is the return value from func1 if no
|
|
|
|
exception occurs, from func2 otherwise.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
VALUE rb_ensure(VALUE (*func1)(), void *arg1, void (*func2)(), void *arg2)
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
Calls the function func1 with arg1 as the argument, then calls func2
|
2002-10-23 12:20:35 +04:00
|
|
|
with arg2 if execution terminated. The return value from
|
1999-08-13 09:45:20 +04:00
|
|
|
rb_ensure() is that of func1.
|
|
|
|
|
|
|
|
** Exceptions and Errors
|
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
void rb_warn(const char *fmt, ...)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Prints a warning message according to a printf-like format.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
void rb_warning(const char *fmt, ...)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Prints a warning message according to a printf-like format, if
|
1999-08-13 09:45:20 +04:00
|
|
|
$VERBOSE is true.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2003-03-20 09:27:22 +03:00
|
|
|
void rb_raise(rb_eRuntimeError, const char *fmt, ...)
|
|
|
|
|
|
|
|
Raises RuntimeError. The fmt is a format string just like printf().
|
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
void rb_raise(VALUE exception, const char *fmt, ...)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Raises a class exception. The fmt is a format string just like printf().
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
void rb_fatal(const char *fmt, ...)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Raises a fatal error, terminates the interpreter. No exception handling
|
|
|
|
will be done for fatal errors, but ensure blocks will be executed.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
void rb_bug(const char *fmt, ...)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-24 12:21:56 +04:00
|
|
|
Terminates the interpreter immediately. This function should be
|
1999-08-13 09:45:20 +04:00
|
|
|
called under the situation caused by the bug in the interpreter. No
|
|
|
|
exception handling nor ensure execution will be done.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2006-09-13 13:49:58 +04:00
|
|
|
** Initialize and Start the Interpreter
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
The embedding API functions are below (not needed for extension libraries):
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-10-04 08:51:08 +04:00
|
|
|
void ruby_init()
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
Initializes the interpreter.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-10-04 08:51:08 +04:00
|
|
|
void ruby_options(int argc, char **argv)
|
|
|
|
|
|
|
|
Process command line arguments for the interpreter.
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
void ruby_run()
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
Starts execution of the interpreter.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
void ruby_script(char *name)
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
Specifies the name of the script ($0).
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2005-03-16 16:05:46 +03:00
|
|
|
** Hooks for the Interpreter Events
|
|
|
|
|
|
|
|
void rb_add_event_hook(rb_event_hook_func_t func, rb_event_t events)
|
|
|
|
|
|
|
|
Adds a hook function for the specified interpreter events.
|
|
|
|
events should be Or'ed value of:
|
|
|
|
|
|
|
|
RUBY_EVENT_LINE
|
|
|
|
RUBY_EVENT_CLASS
|
|
|
|
RUBY_EVENT_END
|
|
|
|
RUBY_EVENT_CALL
|
|
|
|
RUBY_EVENT_RETURN
|
|
|
|
RUBY_EVENT_C_CALL
|
|
|
|
RUBY_EVENT_C_RETURN
|
|
|
|
RUBY_EVENT_RAISE
|
|
|
|
RUBY_EVENT_ALL
|
|
|
|
|
|
|
|
The definition of rb_event_hook_func_t is below:
|
|
|
|
|
|
|
|
typedef void (*rb_event_hook_func_t)(rb_event_t event, NODE *node,
|
|
|
|
VALUE self, ID id, VALUE klass)
|
|
|
|
|
|
|
|
int rb_remove_event_hook(rb_event_hook_func_t func)
|
|
|
|
|
|
|
|
Removes the specified hook function.
|
|
|
|
|
2001-11-29 18:30:54 +03:00
|
|
|
Appendix C. Functions Available in extconf.rb
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
These functions are available in extconf.rb:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2005-03-31 17:24:27 +04:00
|
|
|
have_macro(macro, headers)
|
|
|
|
|
|
|
|
Checks whether macro is defined with header. Returns true if the macro
|
|
|
|
is defined.
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
have_library(lib, func)
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Checks whether the library exists, containing the specified function.
|
1999-01-20 07:59:39 +03:00
|
|
|
Returns true if the library exists.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2001-05-10 22:38:11 +04:00
|
|
|
find_library(lib, func, path...)
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Checks whether a library which contains the specified function exists in
|
2001-05-10 22:38:11 +04:00
|
|
|
path. Returns true if the library exists.
|
|
|
|
|
2000-07-07 07:20:53 +04:00
|
|
|
have_func(func, header)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-07-07 07:20:53 +04:00
|
|
|
Checks whether func exists with header. Returns true if the function
|
2002-10-23 12:20:35 +04:00
|
|
|
exists. To check functions in an additional library, you need to
|
2005-03-31 17:24:27 +04:00
|
|
|
check that library first using have_library().
|
|
|
|
|
|
|
|
have_var(var, header)
|
|
|
|
|
|
|
|
Checks whether var exists with header. Returns true if the variable
|
|
|
|
exists. To check variables in an additional library, you need to
|
2000-07-07 07:20:53 +04:00
|
|
|
check that library first using have_library().
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
have_header(header)
|
|
|
|
|
2001-05-10 22:38:11 +04:00
|
|
|
Checks whether header exists. Returns true if the header file exists.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2005-03-31 17:24:27 +04:00
|
|
|
find_header(header, path...)
|
|
|
|
|
|
|
|
Checks whether header exists in path. Returns true if the header file
|
|
|
|
exists.
|
|
|
|
|
|
|
|
have_struct_member(type, member, header)
|
|
|
|
|
|
|
|
Checks whether type has member with header. Returns true if the type
|
|
|
|
is defined and has the member.
|
|
|
|
|
|
|
|
have_type(type, header, opt)
|
|
|
|
|
|
|
|
Checks whether type is defined with header. Returns true if the type
|
|
|
|
is defined.
|
|
|
|
|
|
|
|
check_sizeof(type, header)
|
|
|
|
|
|
|
|
Checks the size of type in char with header. Returns the size if the
|
|
|
|
type is defined, otherwise nil.
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
create_makefile(target)
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
Generates the Makefile for the extension library. If you don't invoke
|
|
|
|
this method, the compilation will not be done.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2005-03-31 17:24:27 +04:00
|
|
|
find_executable(bin, path)
|
|
|
|
|
|
|
|
Finds command in path, which is File::PATH_SEPARATOR-separated list of
|
|
|
|
directories. If path is nil or omitted, environment varialbe PATH
|
|
|
|
will be used. Returns the path name of the command if it is found,
|
|
|
|
otherwise nil.
|
|
|
|
|
2001-05-10 22:38:11 +04:00
|
|
|
with_config(withval[, default=nil])
|
|
|
|
|
|
|
|
Parses the command line options and returns the value specified by
|
|
|
|
--with-<withval>.
|
|
|
|
|
2005-03-31 17:24:27 +04:00
|
|
|
enable_config(config, *defaults)
|
|
|
|
disable_config(config, *defaults)
|
|
|
|
|
|
|
|
Parses the command line options for boolean. Returns true if
|
|
|
|
--enable-<config> is given, or false if --disable-<config> is given.
|
|
|
|
Otherwise, yields defaults to the given block and returns the result
|
|
|
|
if it is called with a block, or returns defaults.
|
|
|
|
|
2001-05-10 22:38:11 +04:00
|
|
|
dir_config(target[, default_dir])
|
|
|
|
dir_config(target[, default_include, default_lib])
|
|
|
|
|
|
|
|
Parses the command line options and adds the directories specified by
|
|
|
|
--with-<target>-dir, --with-<target>-include, and/or --with-<target>-lib
|
|
|
|
to $CFLAGS and/or $LDFLAGS. --with-<target>-dir=/path is equivalent to
|
|
|
|
--with-<target>-include=/path/include --with-<target>-lib=/path/lib.
|
|
|
|
Returns an array of the added directories ([include_dir, lib_dir]).
|
|
|
|
|
2005-03-31 17:24:27 +04:00
|
|
|
pkg_config(pkg)
|
|
|
|
|
2006-09-13 13:49:58 +04:00
|
|
|
Obtains the information for pkg by pkg-config command. The actual
|
2005-03-31 17:24:27 +04:00
|
|
|
command name can be overriden by --with-pkg-config command line
|
|
|
|
option.
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
/*
|
|
|
|
* Local variables:
|
1999-08-13 09:45:20 +04:00
|
|
|
* fill-column: 70
|
1998-01-16 15:13:05 +03:00
|
|
|
* end:
|
|
|
|
*/
|