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
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Data in Ruby are represented by 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
|
|
|
|
some machines), which can be convert to a C integer by using the
|
|
|
|
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
|
|
|
|
be used to retrieve the double float value in same way.
|
|
|
|
|
|
|
|
To get char* from a VALUE, version 1.7 recommend to use new macros
|
|
|
|
StringValue() and StringValuePtr(). StringValue(var) replaces var's
|
|
|
|
value to 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
|
|
|
|
requires to take only lvalue as their argument, to change the value
|
|
|
|
of var in the replacement.
|
|
|
|
|
|
|
|
In version 1.6 or earlier, STR2CSTR() was used to do same thing
|
|
|
|
but now it is obsoleted in version 1.7 because of STR2CSTR() has
|
|
|
|
a risk of dangling pointer problem in 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
|
2002-10-23 12:20:35 +04:00
|
|
|
for T_ARRAY etc. The VALUE of the type which has 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
|
|
|
|
2004-03-03 07:55:35 +03:00
|
|
|
For example, `RSTRING(str)->len' is the way to get the size of the
|
1999-01-20 07:59:39 +03:00
|
|
|
Ruby String object. The allocated region can be accessed by
|
2002-10-23 12:20:35 +04:00
|
|
|
`RSTRING(str)->ptr'. For arrays, use `RARRAY(ary)->len' and
|
1999-01-20 07:59:39 +03:00
|
|
|
`RARRAY(ary)->ptr' 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
|
|
|
|
array. They may dump core if other types given.
|
|
|
|
|
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,
|
|
|
|
which must be less than 17. But I believe you don't need that much. :-)
|
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
|
1999-01-20 07:59:39 +03:00
|
|
|
defined in Math module. It can be call in the form like:
|
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
|
|
|
|
2000-07-10 08:49:24 +04:00
|
|
|
To define alias to the method,
|
|
|
|
|
|
|
|
void rb_define_alias(VALUE module, const char* new, const char* old);
|
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
|
|
|
|
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
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
You can invoke methods directly, without parsing the string. First I
|
2002-10-23 12:20:35 +04:00
|
|
|
need to explain about symbols (whose data type is ID). ID is the
|
1999-01-20 07:59:39 +03:00
|
|
|
integer number to represent Ruby's identifiers such as variable names.
|
2002-10-23 12:20:35 +04:00
|
|
|
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
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
You can get the symbol 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
|
|
|
|
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);
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
3.3 Encapsulate C data into 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
|
|
|
|
|
|
|
(2) create MANIFEST file
|
|
|
|
|
|
|
|
% cd ext/dbm
|
|
|
|
% touch MANIFEST
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
There should be MANIFEST file in the directory for the extension
|
2002-10-23 12:20:35 +04:00
|
|
|
library. Make an empty file for now.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
(3) design the library
|
|
|
|
|
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
|
|
|
|
|
|
|
(4) write C code.
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
(5) prepare extconf.rb
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
If the file named extconf.rb exists, it will be executed to generate
|
|
|
|
Makefile. If not, the compilation scheme will try to generate Makefile
|
|
|
|
anyway.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
extconf.rb is the file for check 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
|
|
|
|
|
|
|
$CFLAGS: included in CFLAGS make variable (such as -I)
|
|
|
|
$LDFLAGS: included in LDFLAGS make variable (such as -L)
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
If a compilation condition is not fulfilled, you should not call
|
|
|
|
``create_makefile''. The Makefile will not generated, compilation will
|
1999-08-13 09:45:20 +04:00
|
|
|
not be done.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
(6) prepare depend (optional)
|
|
|
|
|
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
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
It's no harm. Prepare it.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
(7) put file names into MANIFEST (optional)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
% find * -type f -print > MANIFEST
|
1998-01-16 15:13:05 +03:00
|
|
|
% vi MANIFEST
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
Append file names into MANIFEST. The compilation scheme requires
|
2002-10-23 12:20:35 +04:00
|
|
|
MANIFEST only to exist, but it's better to take this step in order
|
|
|
|
to distinguish which files are required.
|
1999-08-13 09:45:20 +04:00
|
|
|
|
|
|
|
(8) generate Makefile
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
(9) 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
|
|
|
|
put extension library under the ext directory of the ruby source tree.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
(9) debug
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
You may need to rb_debug the extension. Extensions can be linked
|
|
|
|
statically by the adding directory name in the ext/Setup file so that
|
|
|
|
you can inspect the extension with the debugger.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
(10) 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)
|
|
|
|
STR2CSTR(value)
|
|
|
|
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
|
|
|
|
rb_define_variable(), except 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
|
2000-03-06 07:15:42 +03:00
|
|
|
referred. The setter function is called when the value is set to the
|
1999-01-20 07:59:39 +03:00
|
|
|
variable. The prototype for getter/setter functions are:
|
|
|
|
|
|
|
|
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
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
** Initialize and Starts 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
|
|
|
|
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
|
|
|
|
|
|
|
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
|
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
|
|
|
|
|
|
|
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
|
|
|
|
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>.
|
|
|
|
|
|
|
|
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]).
|
|
|
|
|
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:
|
|
|
|
*/
|