diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1999-08-13 05:45:20 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1999-08-13 05:45:20 +0000 |
commit | 65a5162550f58047974793cdc8067a970b2435c0 (patch) | |
tree | 082bb7d5568f3b2e36e3fe166e9f3039394fcf44 /README.EXT | |
parent | fcd020c83028f5610d382e85a2df00223e12bd7e (diff) | |
download | ruby-65a5162550f58047974793cdc8067a970b2435c0.tar.gz |
1.4.0
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@520 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'README.EXT')
-rw-r--r-- | README.EXT | 492 |
1 files changed, 224 insertions, 268 deletions
diff --git a/README.EXT b/README.EXT index f169e54995..241d6fa8cd 100644 --- a/README.EXT +++ b/README.EXT @@ -1,8 +1,8 @@ .\" README.EXT - -*- Text -*- created at: Mon Aug 7 16:45:54 JST 1995 -This document explains how to make extention modules for Ruby. +This document explains how to make extention libraries for Ruby. -1.Basic knowledge +1. Basic knowledge In C, variables have types and data do not have types. In contrast, Ruby variables do not have static type and data themselves have @@ -109,35 +109,29 @@ bugs. 1.4 Convert C data into VALUE -VALUEの実際の構造は +To convert C data to the values of Ruby: - * FIXNUMの場合 + * FIXNUM - 1bit右シフトして,LSBを立てる. + left shift 1 bit, and turn on LSB. - * その他のポインタの場合 + * Other pointer values - そのままVALUEにキャストする. + cast to VALUE. -となっています.よって,LSBをチェックすればVALUEがFIXNUMかど -うかわかるわけです(ポインタのLSBが立っていないことを仮定して -いる). +You can determine whether VALUE is pointer or not, by checking LSB. -ですから,FIXNUM以外のRubyのオブジェクトの構造体は単にVALUE -にキャストするだけでVALUEに変換出来ます.ただし,任意の構造 -体がVALUEにキャスト出来るわけではありません.キャストするの -はRubyの知っている構造体(ruby.hで定義されているstruct RXxxx -のもの)だけにしておいてください. +Notice Ruby does not allow arbitrary pointer value to be VALUE. They +should be pointers to the structures which Ruby knows. The known +structures are defined in <ruby.h>. -FIXNUMに関しては変換マクロを経由する必要があります.Cの整数 -からVALUEに変換するマクロは以下のものがあります.必要に応じ -て使い分けてください. +To convert C numbers to Ruby value, use these macros. - INT2FIX() もとの整数が31bit以内に収まる時 - INT2NUM() 任意の整数からVALUEへ + INT2FIX() for intergers within 31bits. + INT2NUM() for arbitrary sized integer. -INT2NUM()は整数がFIXNUMの範囲に収まらない場合,Bignumに変換 -してくれます(が,少し遅い). +INT2NUM() converts integers into Bignums, if it is out of FIXNUM +range, but bit slower. 1.5 Manipulate Ruby data @@ -190,23 +184,15 @@ interpreter. Useful functions are listed below (not all): 2. Extend Ruby with C -原理的にRubyで書けることはCでも書けます.RubyそのものがCで記 -述されているんですから,当然といえば当然なんですけど.ここで -はRubyの拡張に使うことが多いだろうと予測される機能を中心に紹 -介します. - 2.1 Add new features to Ruby -Rubyで提供されている関数を使えばRubyインタプリタに新しい機能 -を追加することができます.Rubyでは以下の機能を追加する関数が -提供されています. +You can add new features (classes, methods, etc.) to the Ruby +interpreter. Ruby provides the API to define things below: * Classes, Modules * Methods, Singleton Methods * Constants -では順に紹介します. - 2.1.1 Class/module definition To define class or module, use functions below: @@ -327,9 +313,9 @@ by the symbol mid. 2.2.4 Accessing the variables and constants -Cから関数を使って参照・更新できるのは,クラス定数,インスタ -ンス変数です.大域変数は一部のものはCの大域変数としてアクセ -スできます.ローカル変数を参照する方法は公開していません. +You can access class variables, and instance variables using access +functions. Also, global variables can be shared between both worlds. +There's no way to access Ruby's local variables. The functions to access/modify instance variables are below: @@ -346,9 +332,7 @@ See 2.1.3 for defining new constant. 3. Informatin sharing between Ruby and C -C言語とRubyの間で情報を共有する方法について解説します. - -3.1 Ruby constant that Cから参照できるRubyの定数 +3.1 Ruby constant that C can be accessed from C Following Ruby constants can be referred from C. @@ -363,43 +347,35 @@ Ruby nil in C scope. 3.2 Global variables shared between C and Ruby -CとRubyで大域変数を使って情報を共有できます.共有できる大域 -変数にはいくつかの種類があります.そのなかでもっとも良く使わ -れると思われるのはrb_define_variable()です. +Information can be shared between two worlds, using shared global +variables. To define them, you can use functions listed below: void rb_define_variable(char *name, VALUE *var) -この関数はRubyとCとで共有する大域変数を定義します.変数名が -`$'で始まらない時には自動的に追加されます.この変数の値を変 -更すると自動的にRubyの対応する変数の値も変わります. +This function defines the variable which is shared by the both world. +The value of the global variable pointerd by `var', can be accessed +through Ruby's global variable named `name'. -またRuby側からは更新できない変数もあります.このread onlyの -変数は以下の関数で定義します. +You can define read-only (from Ruby, of course) variable by the +function below. void rb_define_readonly_variable(char *name, VALUE *var) -これら変数の他にhookをつけた大域変数を定義できます.hook付き -の大域変数は以下の関数を用いて定義します.hook付き大域変数の -値の参照や設定はhookで行う必要があります. +You can defined hooked variables. The accessor functions (getter and +setter) are called on access to the hooked variables. void rb_define_hooked_variable(char *name, VALUE *var, VALUE (*getter)(), VALUE (*setter)()) -この関数はCの関数によってhookのつけられた大域変数を定義しま -す.変数が参照された時には関数getterが,変数に値がセットされ -た時には関数setterが呼ばれる.hookを指定しない場合はgetterや -setterに0を指定します. - -# getterもsetterも0ならばrb_define_variable()と同じになる. - -それから,Cの関数によって実現されるRubyの大域変数を定義する -関数があります. +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(). void rb_define_virtual_variable(char *name, VALUE (*getter)(), VALUE (*setter)()) -この関数によって定義されたRubyの大域変数が参照された時には -getterが,変数に値がセットされた時にはsetterが呼ばれます. +This function defines the Ruby global variable without corresponding C +variable. The value of the variable will be set/get only by hooks. The prototypes of the getter and setter functions are as following: @@ -408,54 +384,44 @@ The prototypes of the getter and setter functions are as following: 3.3 Encapsulate C data into Ruby object -Cの世界で定義されたデータ(構造体)をRubyのオブジェクトとして -取り扱いたい場合がありえます.このような場合には,Dataという -RubyオブジェクトにCの構造体(へのポインタ)をくるむことでRuby -オブジェクトとして取り扱えるようになります. - -Dataオブジェクトを生成して構造体をRubyオブジェクトにカプセル -化するためには,以下のマクロを使います. +To wrapping and objectify the C pointer as Ruby object (so called +DATA), use Data_Wrap_Struct(). Data_Wrap_Struct(class,mark,free,ptr) -このマクロの戻り値は生成されたDataオブジェクトです. - -classはこのDataオブジェクトのクラスです.ptrはカプセル化する -Cの構造体へのポインタです.markはこの構造体がRubyのオブジェ -クトへの参照がある時に使う関数です.そのような参照を含まない -時には0を指定します. +Data_Wrap_Struct() returns a created DATA object. The class argument +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 +function to free the pointer allocation. The functions, mark and +free, will be called from garbage collector. -# そのような参照は勧められません. - -freeはこの構造体がもう不要になった時に呼ばれる関数です.この -関数がガーベージコレクタから呼ばれます. - -Cの構造体の割当とDataオブジェクトの生成を同時に行うマクロと -して以下のものが提供されています. +You can allocate and wrap the structure in one step. Data_Make_Struct(class, type, mark, free, sval) -このマクロの戻り値は生成されたDataオブジェクトです. +This macro returns an allocated Data object, wrapping the pointer to +the structure, which is also allocated. This macro works like: + + (sval = ALLOC(type), Data_Wrap_Struct(class, mark, free, sval)) -class, mark, freeはData_Wrap_Structと同じ働きをします.type -は割り当てるC構造体の型です.割り当てられた構造体は変数sval -に代入されます.この変数の型は (type*) である必要があります. +Arguments, class, mark, free, works like thier counterpart of +Data_Wrap_Struct(). The pointer to allocated structure will be +assigned to sval, which should be the pointer to the type specified. -Dataオブジェクトからポインタを取り出すのは以下のマクロを用い -ます. +To retrieve the C pointer from the Data object, use the macro +Data_Get_Struct(). Data_Get_Struct(obj, type, sval) -Cの構造体へのポインタは変数svalに代入されます. +The pointer to the structure will be assigned to the variable sval. -これらのDataの使い方はちょっと分かりにくいので,後で説明する -例題を参照してください. +See example below for detail. -4.Example - Create dbm module +4. Example - Creating dbm extension -ここまでの説明でとりあえず拡張ライブラリは作れるはずです. -Rubyのextディレクトリにすでに含まれているdbmモジュールを例に -して段階的に説明します. +OK, here's the example to make extension library. This is the +extension to access dbm. The full source is included in ext/ +directory in the Ruby's source tree. (1) make the directory @@ -477,17 +443,17 @@ You need to design the library features, before making it. (4) write C code. -拡張ライブラリ本体となるC言語のソースを書きます.C言語のソー -スがひとつの時には「モジュール名.c」を選ぶと良いでしょう.C -言語のソースが複数の場合には逆に「モジュール名.c」というファ -イル名は避ける必要があります.オブジェクトファイルとモジュー -ル生成時に中間的に生成される「モジュール名.o」というファイル -とが衝突するからです. +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 +preferred. On the other hand, in case your library has prural source +files, avoid chooing ``LIBRARY.c'' for a file name. It may conflict +with intermediate file ``LIBRARY.o'' on some platforms. -Rubyは拡張ライブラリをロードする時に「Init_モジュール名」と -いう関数を自動的に実行します.dbmモジュールの場合「Init_dbm」 -です.この関数の中でクラス,モジュール,メソッド,定数などの -定義を行います.dbm.cから一部引用します. +Ruby will execute the initializing function named ``Init_LIBRARY'' in +the library. For exapmle, ``Init_dbm()'' will be executed when loading +the library. + +Here's the example of an initializing function. -- Init_dbm() @@ -509,11 +475,7 @@ Init_dbm() } -- -DBMモジュールはdbmのデータと対応するオブジェクトになるはずで -すから,Cの世界のdbmをRubyの世界に取り込む必要があります. - - -dbm.cではData_Make_Structを以下のように使っています. +The dbm extension wrap dbm struct in C world using Data_Make_Struct. -- struct dbmdata { @@ -525,12 +487,10 @@ struct dbmdata { obj = Data_Make_Struct(class,struct dbmdata,0,free_dbm,dbmp); -- -ここではdbmstruct構造体へのポインタをDataにカプセル化してい -ます.DBM*を直接カプセル化しないのはclose()した時の処理を考 -えてのことです. +This code wraps dbmdata structure into Ruby object. We avoid wrapping +DBM* directly, because we want to cache size information. -Dataオブジェクトからdbmstruct構造体のポインタを取り出すため -に以下のマクロを使っています. +To retrieve dbmdata structure from Ruby object, we define the macro below: -- #define GetDBM(obj, dbmp) {\ @@ -539,14 +499,11 @@ Dataオブジェクトからdbmstruct構造体のポインタを取り出すため } -- -ちょっと複雑なマクロですが,要するにdbmdata構造体のポインタ -の取り出しと,closeされているかどうかのチェックをまとめてい -るだけです. +This sort of complicated macro do the retrieving and close check for +the DBM. -DBMクラスにはたくさんメソッドがありますが,分類すると3種類の -引数の受け方があります.ひとつは引数の数が固定のもので,例と -してはdeleteメソッドがあります.deleteメソッドを実装している -fdbm_delete()はこのようになっています. +There are three kind of way to receiving method arguments. First, the +methods with fixed number of arguments receives arguments like this: -- static VALUE @@ -557,13 +514,11 @@ fdbm_delete(obj, keystr) } -- -引数の数が固定のタイプは第1引数がself,第2引数以降がメソッド -の引数となります. +The first argument of the C function is the self, the rest are the +arguments to the method. -引数の数が不定のものはCの配列で受けるものとRubyの配列で受け -るものとがあります.dbmモジュールの中で,Cの配列で受けるもの -はDBMのクラスメソッドであるopen()です.これを実装している関 -数fdbm_s_open()はこうなっています. +Second, the methods with arbtrary number of arguments receives +arguments like this: -- static VALUE @@ -580,36 +535,28 @@ fdbm_s_open(argc, argv, class) } -- -このタイプの関数は第1引数が与えられた引数の数,第2引数が与え -られた引数の入っている配列になります.selfは第3引数として与 -えられます. +The first argument is the number of method arguments. the second +argument is the C array of the method arguments. And the third +argument is the receiver of the method. -この配列で与えられた引数を解析するための関数がopen()でも使わ -れているrb_scan_args()です.第3引数に指定したフォーマットに -従い,第4変数以降に指定した変数に値を代入してくれます.この -フォーマットは,第1文字目が省略できない引数の数,第2文字目が -省略できる引数の数,第3文字目が対応する相手が無いあまりの引 -数があるかどうかを示す"*"です.2文字目と3文字目は省略できま -す.dbm.cの例では,フォーマットは"11"ですから,引数は最低1つ -で,2つまで許されるという意味になります.省略されている時の -変数の値はnil(C言語のレベルではQnil)になります. +You can use the function rb_scan_args() to check and retrieve the +arguments. For exapmle "11" means, the method requires at least one +argument, and at most receives two arguments. -Rubyの配列で引数を受け取るものはindexesがあります.実装はこ -うです. +The methods with arbtrary number of arguments can receives arguments +by Ruby's array, like this: -- static VALUE fdbm_indexes(obj, args) - VALUE obj; - struct RArray *args; + VALUE obj, args; { : } -- -第1引数はself,第2引数はRubyの配列です.ここではキャストを減 -らすため struct RArray* で受けていますが,VALUEでも同じこと -です. +The first argument is the receiver, the second one is the Ruby array +which contains the arguments to the method. ** Notice @@ -620,72 +567,82 @@ not exported to the Ruby world. You need to protect them by (5) prepare extconf.rb -もしディレクトリに「extconf.rb」というファイルが存在すれば, -make時に実行されます.なければ適当にMakefileが生成されます. +If there exists the file named extconf.rb, it will be executed to +generate Makefile. If not, compilation scheme try to generate +Makefile anyway. -extconf.rbはモジュールのコンパイルに必要な条件のチェックなど -を行うことが目的です.extconf.rbの中では以下のRuby関数を使う -ことが出来ます. +The extconf.rb is the file to check compilation condition etc. You +need to put - have_library(lib, func): ライブラリの存在チェック - have_func(func): 関数の存在チェック - have_header(header): ヘッダファイルの存在チェック - create_makefile(target): Makefileの生成 + require 'mkmf' -以下の変数を使うことができます. +at the top of the file. You can use the funcitons below to check the +condition. - $CFLAGS: コンパイル時に追加的に指定するフラグ(-Iなど) - $LDFLAGS: リンク時に追加的に指定するフラグ(-Lなど) + have_library(lib, func): check whether library containing function exists. + have_func(func): check whether function exists + have_header(header): check whether header file exists + create_makefile(target): generate Makefile -モジュールをコンパイルする条件が揃わなず,そのモジュールはコ -ンパイルしない時にはcreate_makefileを呼ばなければMakefileは -生成されず,コンパイルも行われません. +The value of variables below will affect Makefile. + + $CFLAGS: included in CFLAGS make variable (such as -I) + $LDFLAGS: included in LDFLAGS make variable (such as -L) + +If compilation condition is not fulfilled, you do not call +``create_makefile''. Makefile will not generated, compilation will +not be done. (6) prepare depend (optional) -もし,ディレクトリにdependというファイルが存在すれば, -Makefileが依存関係をチェックしてくれます. +If the file named depend exists, Makefile will include that file to +check dependency. You can make this file by invoking % gcc -MM *.c > depend -などで作ることが出来ます.あって損は無いでしょう. +It's no harm. Prepare it. -(7) MANIFESTファイルにファイル名を入れる +(7) put file names into MANIFEST (optional) - % ls > MANIFEST + % find * -type f -print > MANIFEST % vi MANIFEST -*.o, *~など不必要なファイル以外はMANIFESTに追加しておきます. -make時にはMANIFESTの内容は参照しませんので,空のままでも問題 -は起きませんが,パッケージングの時に参照することがあるのと, -必要なファイルを区別できるので,用意しておいた方が良いでしょ -う. +Append file names into MANIFEST. The compilation scheme requires +MANIFEST only to be exist. But, you'd better take this step to +distinguish required files. + +(8) generate Makefile + +Try generate Makefile by: + + ruby extconf.rb + +You don't need this step, if you put extension library under ext +directory of the ruby source tree. In that case, compilation of the +interpreter will do this step for you. + +(9) make -(8) make +Type -Rubyのディレクトリでmakeを実行するとMakefileを生成からmake, -必要によってはそのモジュールのRubyへのリンクまで自動的に実行 -してくれます.extconf.rbを書き換えるなどしてMakefileの再生成 -が必要な時はまたRubyディレクトリでmakeしてください. + make + +to compile your extension. You don't need this step neither, if you +put extension library under ext directory of the ruby source tree. (9) debug -You may need to rb_debug the module. The modules can be linked -statically by adding directory name in the ext/Setup file, -so that you can inspect the module by the debugger. +You may need to rb_debug the extension. The extensions can be linked +statically by adding directory name in the ext/Setup file, so that you +can inspect the extension with the debugger. (10) done, now you have the extension library -後はこっそり使うなり,広く公開するなり,売るなり,ご自由にお -使いください.Rubyの作者は拡張ライブラリに関して一切の権利を -主張しません. - -Appendix A. Rubyのソースコードの分類 +You can do anything you want with your library. The author of Ruby +will not claim any restriction about your code depending Ruby API. +Feel free to use, modify, distribute or sell your program. -Rubyのソースはいくつかに分類することが出来ます.このうちクラ -スライブラリの部分は基本的に拡張ライブラリと同じ作り方になっ -ています.これらのソースは今までの説明でほとんど理解できると -思います. +Appendix A. Ruby source files overview ruby language core @@ -737,18 +694,15 @@ class library struct.c time.c -Appendix B. 拡張用関数リファレンス - -C言語からRubyの機能を利用するAPIは以下の通りである. +Appendix B. Ruby extension API reference -** 型 +** Types VALUE -Rubyオブジェクトを表現する型.必要に応じてキャストして用いる. -組み込み型を表現するCの型はruby.hに記述してあるRで始まる構造 -体である.VALUE型をこれらにキャストするためにRで始まる構造体 -名を全て大文字にした名前のマクロが用意されている. +The type for Ruby object. Actual structures are defined in ruby.h, +such as struct RString, etc. To refer the values in structures, use +casting macros like RSTRING(obj). ** Variables and constants @@ -758,58 +712,58 @@ const: nil object Qtrue -const: Qtrue object(default true value) +const: true object(default true value) Qfalse -const: Qfalse object +const: false object -** Cデータのカプセル化 +** C pointer wrapping Data_Wrap_Struct(VALUE class, void (*mark)(), void (*free)(), void *sval) -Cの任意のポインタをカプセル化したRubyオブジェクトを返す.こ -のポインタがRubyからアクセスされなくなった時,freeで指定した -関数が呼ばれる.また,このポインタの指すデータが他のRubyオブ -ジェクトを指している場合,markに指定する関数でマークする必要 -がある. +Wrap C pointer into Ruby object. If object has references to other +Ruby object, they should be marked by using mark function during GC +process. Otherwise, mark should be 0. When this object is no longer +referred by anywhere, the pointer will be discarded by free function. Data_Make_Struct(class, type, mark, free, sval) -type型のメモリをmallocし,変数svalに代入した後,それをカプセ -ル化したデータを返すマクロ. +This macro allocates memory using malloc(), assigns it to the variable +sval, and returns the DATA encapsulating the pointer to memory region. Data_Get_Struct(data, type, sval) -dataからtype型のポインタを取り出し変数svalに代入するマクロ. +This macro retrieves the pointer value from DATA, and assigns it to +the variable sval. -** クラス/モジュール定義 +** defining class/module VALUE rb_define_class(char *name, VALUE super) -superのサブクラスとして新しいRubyクラスを定義する. +Defines new Ruby class as subclass of super. VALUE rb_define_class_under(VALUE module, char *name, VALUE super) -superのサブクラスとして新しいRubyクラスを定義し,moduleの定 -数として定義する. +Creates new Ruby class as subclass of super, under the module's +namespace. VALUE rb_define_module(char *name) -新しいRubyモジュールを定義する. +Defines new Ruby module. VALUE rb_define_module_under(VALUE module, char *name, VALUE super) -新しいRubyモジュールを定義し,moduleの定数として定義する. +Defines new Ruby module, under the modules's namespace. void rb_include_module(VALUE class, VALUE module) -モジュールをインクルードする.classがすでにmoduleをインクルー -ドしている時には何もしない(多重インクルードの禁止). +Includes module into class. If class already includes it, just +ignore. void rb_extend_object(VALUE object, VALUE module) -オブジェクトをモジュール(で定義されているメソッド)で拡張する. +Extend the object with module's attribute. ** Defining Global Variables @@ -871,115 +825,118 @@ Defines global contant. This is just work as rb_define_method(VALUE class, char *name, VALUE (*func)(), int argc) -メソッドを定義する.argcはselfを除く引数の数.argcが-1の時, -関数には引数の数(selfを含まない)を第1引数, 引数の配列を第2引 -数とする形式で与えられる(第3引数はself).argcが-2の時, 第1引 -数がself, 第2引数がargs(argsは引数を含むRubyの配列)という形 -式で与えられる. +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 +3 arguments argc, argv, and self. if argc is -2, the function will +receive 2 arguments, self and args, where args is the Ruby array of +the method arguments. rb_define_private_method(VALUE class, char *name, VALUE (*func)(), int argc) -privateメソッドを定義する.引数はrb_define_method()と同じ. +Defines a private method for the class. Arguments are same as +rb_define_method(). rb_define_singleton_method(VALUE class, char *name, VALUE (*func)(), int argc) -特異メソッドを定義する.引数はrb_define_method()と同じ. +Defines a singleton method. Arguments are same as rb_define_method(). - rb_scan_args(int atgc, VALUE *argv, char *fmt, ...) + rb_scan_args(int argc, VALUE *argv, char *fmt, ...) -argc,argv形式で与えられた引数を分解する.fmtは必須引数の数, -付加引数の数, 残りの引数があるかを指定する文字列で, "数字数 -字*"という形式である. 2 番目の数字と"*"はそれぞれ省略可能で -ある.必須引数が一つもない場合は0を指定する.第3引数以降は変 -数へのポインタで, 該当する要素がその変数に格納される.付加引 -数に対応する引数が与えられていない場合は変数にQnilが代入され -る. +Retrieve argument from argc, argv. The fmt is the format string for +the arguments, such as "12" for 1 non-optinal argument, 2 optinal +aruguments. If `*' appears at the end of fmt, it means the rest of +the arguments are assigned to corresponding variable, packed in +array. -** Rubyメソッド呼び出し +** Invoking Ruby method VALUE rb_funcall(VALUE recv, ID mid, int narg, ...) -メソッド呼び出し.文字列からmidを得るためにはrb_intern()を使う. +Invokes the method. To retrieve mid from method name, use rb_intern(). VALUE rb_funcall2(VALUE recv, ID mid, int argc, VALUE *argv) -メソッド呼び出し.引数をargc,argv形式で渡す. +Invokes method, passing arguments by array of values. VALUE rb_eval_string(char *str) -文字列をRubyとスクリプトしてコンパイル・実行する. +Compiles and executes the string as Ruby program. ID rb_intern(char *name) -文字列に対応するIDを返す. +Returns ID corresponding the name. char *rb_id2name(ID id) -IDに対応する文字列を返す(デバッグ用). +Returns the name corresponding ID. char *rb_class2name(VALUE class) -classの名前を返す(デバッグ用).classが名前を持たない時には, -祖先を遡って名前を持つクラスの名前を返す. +Returns the name of the class. -** インスタンス変数 +** Instance Variables VALUE rb_iv_get(VALUE obj, char *name) -objのインスタンス変数の値を得る.`@'で始まらないインスタンス -変数は Rubyプログラムからアクセスできない「隠れた」インスタ -ンス変数になる. +Retrieve the value of the instance variable. If the name is not +prefixed by `@', that variable shall be inaccessible from Ruby. VALUE rb_iv_set(VALUE obj, char *name, VALUE val) -objのインスタンス変数をvalにセットする. +Sets the value of the instance variable. -** 制御構造 +** Control Structure VALUE rb_iterate(VALUE (*func1)(), void *arg1, VALUE (*func2)(), void *arg2) -func2をブロックとして設定し, func1をイテレータとして呼ぶ. -func1には arg1が引数として渡され, func2には第1引数にイテレー -タから与えられた値, 第2引数にarg2が渡される. +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. + VALUE rb_yield(VALUE val) -valを値としてイテレータブロックを呼び出す. +Evaluates the block with value val. VALUE rb_rescue(VALUE (*func1)(), void *arg1, VALUE (*func2)(), void *arg2) -関数func1をarg1を引数に呼び出す.func1の実行中に例外が発生し -た時には func2をarg2を引数として呼ぶ.戻り値は例外が発生しな -かった時はfunc1の戻り値, 例外が発生した時にはfunc2の戻り値で -ある. +Calls the function func1, with arg1 as the argument. If exception +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. VALUE rb_ensure(VALUE (*func1)(), void *arg1, void (*func2)(), void *arg2) -関数func1をarg1を引数として実行し, 実行終了後(たとえ例外が発 -生しても) func2をarg2を引数として実行する.戻り値はfunc1の戻 -り値である(例外が発生した時は戻らない). +Calls the function func1 with arg1 as the argument, then calls func2 +with arg2, whenever execution terminated. The return value from +rb_ensure() is that of func1. + +** Exceptions and Errors + + void rb_warn(char *fmt, ...) -** 例外・エラー +Prints warning message according to the printf-like format. void rb_warning(char *fmt, ...) -rb_verbose時に標準エラー出力に警告情報を表示する.引数はprintf()と同じ. +Prints warning message according to the printf-like format, if +$VERBOSE is true. - void rb_raise(rb_eRuntimeError, char *fmt, ...) + void rb_raise(VALUE exception, char *fmt, ...) -例外を発生させる.引数はprintf()と同じ. +Raises an exception of class exception. The fmt is the format string +just like printf(). void rb_fatal(char *fmt, ...) -致命的例外を発生させる.通常の例外処理は行なわれず, インター -プリタが終了する(ただしensureで指定されたコードは終了前に実 -行される). +Raises fatal error, terminates the interpreter. No exception handling +will be done for fatal error, but ensure blocks will be executed. void rb_bug(char *fmt, ...) -インタープリタなどプログラムのバグでしか発生するはずのない状 -況の時呼ぶ.インタープリタはコアダンプし直ちに終了する.例外 -処理は一切行なわれない. +Termintates the interpreter immediately. This function should be +called under the situation caused by the bug in the interpreter. No +exception handling nor ensure execution will be done. ** Initialize and Starts the Interpreter @@ -999,8 +956,7 @@ Specifies the name of the script ($0). Appendix B. Functions Available in extconf.rb -extconf.rbの中では利用可能なコンパイル条件チェックの関数は以 -下の通りである. +These functions are available in extconf.rb: have_library(lib, func) @@ -1024,6 +980,6 @@ this method, the compilation will not be done. /* * Local variables: - * fill-column: 60 + * fill-column: 70 * end: */ |