aboutsummaryrefslogtreecommitdiffstats
path: root/README.EXT
blob: c2f81d1a7a5abc9d51b743396186c8d780100254 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
.\" README.EXT -  -*- Text -*- created at: Mon Aug  7 16:45:54 JST 1995

This document explains how to make extention modules for ruby.

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
types.  So, data need to be converted across the languages.

Data in ruby represented C type `VALUE'.  Each VALUE data have its
data-type.

ruby�Υǡ�����VALUE�Ȥ���C�η���ɽ������ޤ���VALUE���Υǡ�
���Ϥ��Υǡ��������פ�ʬ���ΤäƤ��ޤ������Υǡ��������פ�
�����Τϥǡ���(���֥�������)�μºݤι�¤���̣���Ƥ��ơ�ruby
�Υ��饹�ȤϤޤ���ä���ΤǤ���

To retrieve an C data from the VALUE, you need to:

 (1) Identify VALUE's data type
 (2) Convert VALUE into C data

Converting to wrong data type may cause serious promblems.


1.1 Data-types

Ruby interpreter has data-types as below:

	T_NIL		nil
	T_OBJECT	ordinaly object
	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)
	T_HASH		assosiative array
	T_STRUCT	(ruby) structure
	T_BIGNUM	multi precision integer
	T_TRUE		true
	T_FALSE		false
	T_DATA		data

Otherwise, there are several other types used internally:

	T_ICLASS
	T_MATCH
	T_VARMAP
	T_SCOPE
	T_NODE

Most of the types are represented by C structures.

1.2 Check Data Type of the VALUE

The macro TYPE() defined in ruby.h shows data-type of the VALUE.
TYPE() returns the constant number T_XXXX described above.  To handle
data-types, the code will be like:

  switch (TYPE(obj)) {
    case T_FIXNUM:
      /* process Fixnum */
      break;
    case T_STRING:
      /* process String */
      break;
    case T_ARRAY:
      /* process Array */
      break;
    default:
      /* raise exception */
      Fail("not valid value");
      break;
  }

There is the data-type check function.

  void Check_Type(VALUE value, int type)

It raises an exception, if the VALUE does not have the type specified.

There are faster check-macros for fixnums and nil.

  FIXNUM_P(obj)
  NIL_P(obj)

1.3 Convert VALUE into C data

�ǡ��������פ�T_NIL, T_FALSE, T_TRUE�Ǥ�������ǡ����Ϥ��줾
��nil, FALSE, TRUE�Ǥ������Υǡ��������פΥ��֥������ȤϤҤ�
�Ĥ��Ĥ���¸�ߤ��ޤ���

�ǡ��������פ�T_FIXNUM�λ��������31bit�Υ����������������
����FIXNUM��C���������Ѵ����뤿��ˤϥޥ�����FIX2INT()�פ��
���ޤ������줫�顤FIXNUM�˸¤餺ruby�Υǡ������������Ѵ�����
��NUM2INT()�פȤ����ޥ���������ޤ������Υޥ����ϥǡ�������
�פΥ����å�̵���ǻȤ��ޤ�(�������Ѵ��Ǥ��ʤ����ˤ��㳰��
ȯ������)��

����ʳ��Υǡ��������פ��б�����C�ι�¤�Τ�����ޤ����б���
�빽¤�ΤΤ���VALUE�Ϥ��Τޤޥ��㥹��(���Ѵ�)����й�¤�Τ�
�ݥ��󥿤��Ѵ��Ǥ��ޤ���

��¤�Τϡ�struct RXxxxx�פȤ���̾����ruby.h���������Ƥ���
�����㤨��ʸ����ϡ�struct RString�פǤ����ºݤ˻Ȥ���ǽ����
����Τ�ʸ��������󤯤餤���Ȼפ��ޤ���

ruby.h�ǤϹ�¤�Τإ��㥹�Ȥ���ޥ������RXXXXX()��(������ʸ
���ˤ������)�Ȥ���̾�����󶡤���Ƥ��ޤ�(��: RSTRING())��

�㤨�С�ʸ����str��Ĺ�������뤿��ˤϡ�RSTRING(str)->len�פ�
����ʸ����str��char*�Ȥ������뤿��ˤϡ�RSTRING(str)->ptr��
�Ȥ��ޤ�������ξ��ˤϡ����줾���RARRAT(str)->len�ס�
��RARRAT(str)->ptr�פȤʤ�ޤ���

ruby�ι�¤�Τ�ľ�ܥ�������������˵���Ĥ��ʤ���Фʤ�ʤ���
�Ȥϡ������ʸ����ι�¤�Τ���Ȥϻ��Ȥ�������ǡ�ľ���ѹ���
�ʤ����ȤǤ���ľ���ѹ�������硤���֥������Ȥ����Ƥ���������
�Ȥ�ʤ��ʤäơ��פ�̥Х��θ����ˤʤ�ޤ���

1.4 Convert C data into VALUE

VALUE�μºݤι�¤��

  * FIXNUM��

    1bit�����եȤ��ơ�LSB��Ω�Ƥ롥

  * ����¾�Υݥ��󥿤ξ��

    ���Τޤ�VALUE�˥��㥹�Ȥ��롥

�ȤʤäƤ��ޤ�����äơ�LSB������å������VALUE��FIXNUM����
�����狼��櫓�Ǥ�(�ݥ��󥿤�LSB��Ω�äƤ��ʤ����Ȥ��ꤷ��
����)��

�Ǥ����顤FIXNUM�ʳ���ruby�Υ��֥������Ȥι�¤�Τ�ñ��VALUE
�˥��㥹�Ȥ��������VALUE���Ѵ�����ޤ�����������Ǥ�դι�¤
�Τ�VALUE�˥��㥹�Ƚ����櫓�ǤϤ���ޤ��󡥥��㥹�Ȥ����
��ruby���ΤäƤ��빽¤��(ruby.h���������Ƥ���struct RXxxx
�Τ��)�����ˤ��Ƥ����Ƥ���������

FIXNUM�˴ؤ��Ƥ��Ѵ��ޥ������ͳ����ɬ�פ�����ޤ���C������
����VALUE���Ѵ�����ޥ����ϰʲ��Τ�Τ�����ޤ���ɬ�פ˱���
�ƻȤ�ʬ���Ƥ���������

  INT2FIX()	��Ȥ�������31bit����˼��ޤ��
  INT2NUM()	Ǥ�դ���������VALUE��

INT2NUM()��������FIXNUM���ϰϤ˼��ޤ�ʤ���硤Bignum���Ѵ�
���Ƥ���ޤ�(���������٤�)��

1.5 Manipulate ruby data

������Ҥ٤��̤ꡤruby�ι�¤�Τ򥢥���������������Ƥι�����
�Ԥ����Ȥϴ�����ޤ��󡥤ǡ�ruby�Υǡ�����������ˤ�
ruby���Ѱդ��Ƥ���ؿ����Ѥ��Ƥ���������

�����ǤϤ�äȤ�Ȥ���Ǥ�����ʸ��������������/�����
���ؿ��򤢤��ޤ�(�����ǤϤʤ��Ǥ�)��

 String funtions

  str_new(char *ptr, int len)

    Creates a new ruby string.

  str_new2(char *ptr)

    Creates a new ruby string from C string.  This is equivalent to
    str_new(ptr, strlen(ptr)).

  str_cat(VALUE str, char *ptr, int len)

    Appends len bytes data from ptr to the ruby string.

 Array functions

  ary_new()

    Creates an array with no element.

  ary_new2(int len)

    Creates an array with no element, with allocating internal buffer
    for len elements.

  ary_new3(int n, ...)

    Creates an n-elements array from arguments.

  ary_new4(int n, VALUE *elts)

    Creates an n-elements array from C array.

  ary_push(VALUE ary)
  ary_pop(VALUE ary, VALUE val)
  ary_shift(VALUE ary)
  ary_unshift(VALUE ary, VALUE val)
  ary_entry(VALUE ary, int idx)

    Array operations.  The first argument to each functions must be an 
    array.  They may dump core if other types given.

2. Extend ruby with C

����Ū��ruby�ǽ񤱤뤳�Ȥ�C�Ǥ�񤱤ޤ���ruby���Τ�Τ�C�ǵ�
�Ҥ���Ƥ����Ǥ����顤�����Ȥ����������ʤ�Ǥ����ɡ�������
��ruby�γ�ĥ�˻Ȥ����Ȥ�¿����������ͽ¬����뵡ǽ���濴�˾�
�𤷤ޤ���

2.1 Add new features to ruby

ruby���󶡤���Ƥ���ؿ���Ȥ���ruby���󥿥ץ꥿�˿�������ǽ
���ɲä��뤳�Ȥ��Ǥ��ޤ���ruby�Ǥϰʲ��ε�ǽ���ɲä���ؿ���
�󶡤���Ƥ��ޤ���

 * ���饹���⥸�塼��
 * �᥽�åɡ��ðۥ᥽�åɤʤ�
 * ���

�ǤϽ�˾Ҳ𤷤ޤ���

2.1.1 Class/module definition

���饹��⥸�塼���������뤿��ˤϡ��ʲ��δؿ���Ȥ��ޤ���

  VALUE rb_define_class(char *name, VALUE super)
  VALUE rb_define_module(char *name)

�����δؿ��Ͽ�����������줿���饹��⥸�塼����֤��ޤ���
�᥽�åɤ����������ˤ������ͤ�ɬ�פʤΤǡ��ۤȤ�ɤξ��
������ͤ��ѿ��˳�Ǽ���Ƥ���ɬ�פ�����Ǥ��礦��

2.1.2 Method/singleton method definition

�᥽�åɤ��ðۥ᥽�åɤ��������ˤϰʲ��δؿ���Ȥ��ޤ���

  void rb_define_method(VALUE class, char *name, 
		        VALUE (*func)(), int argc)

  void rb_define_singleton_method(VALUE object, char *name, 
			         VALUE (*func)(), int argc)


ǰ�Τ�����������ȡ��ðۥ᥽�åɡפȤϡ���������Υ��֥�����
�Ȥ��Ф��Ƥ���ͭ���ʥ᥽�åɤǤ���ruby�ǤϤ褯Smalltalk�ˤ�
���륯�饹�᥽�åɤȤ��ơ����饹���Ф����ðۥ᥽�åɤ��Ȥ��
�ޤ���

�����δؿ��� argc�Ȥ���������C�δؿ����Ϥ��������ο�(��
����)����ޤ���argc�����λ��ϴؿ��˰����Ϥ������ο����̣
���ޤ���16�İʾ�ΰ����ϻȤ��ޤ���(�����פ�ޤ����͡�����
�ʤ�)��

argc����λ��ϰ����ο��ǤϤʤ�����������ꤷ�����Ȥˤʤ�ޤ���
argc��-1�λ��ϰ����������������Ϥ���ޤ���argc��-2�λ��ϰ�
����ruby������Ȥ����Ϥ���ޤ���

�᥽�åɤ��������ؿ��Ϥ⤦��Ĥ���ޤ����ҤȤĤ�private��
���åɤ��������ؿ��ǡ�������rb_define_method()��Ʊ���Ǥ���

  void rb_define_private_method(VALUE class, char *name, 
			        VALUE (*func)(), int argc)

private�᥽�åɤȤϴؿ������Ǥ����ƤӽФ����Ȥν���ʤ��᥽��
�ɤǤ���

�⤦�ҤȤĤϥ⥸�塼��ؿ�����������ΤǤ����⥸�塼��ؿ�
�Ȥϥ⥸�塼����ðۥ᥽�åɤǤ��ꡤƱ����private�᥽�åɤ�
�⤢���ΤǤ�����򤢤����Math�⥸�塼���sqrt()�ʤɤ�����
���ޤ������Υ᥽�åɤ�

  Math.sqrt(4)

�Ȥ��������Ǥ�

  include Math
  sqrt(4)

�Ȥ��������Ǥ�Ȥ��ޤ����⥸�塼��ؿ����������ؿ��ϰʲ���
�̤�Ǥ���

  void rb_define_module_function(VALUE module, char *name, 
				 VALUE (*func)(), int argc)

�ؿ�Ū�᥽�å�(Kernel�⥸�塼���privaet method)��������뤿
��δؿ��ϰʲ����̤�Ǥ���

  void rb_define_global_function(char *name, VALUE (*func)(), int argc)


2.1.3 Constant definition

��ĥ�⥸�塼�뤬ɬ�פ�����Ϥ��餫����������Ƥ����������ɤ�
�Ǥ��礦��������������ؿ�����Ĥ���ޤ���

  void rb_define_const(VALUE class, char *name, VALUE val)
  void rb_define_global_const(char *name, VALUE val)

���Ԥ�����Υ��饹/�⥸�塼���°�����������������Ρ���
�Ԥϥ������Х���������������ΤǤ���

2.2 Use ruby features from C

���ˡ�1.5 ruby�Υǡ���������٤ǰ����Ҳ𤷤��褦�ʴؿ���
�Ȥ��С�ruby�ε�ǽ��¸����Ƥ���ؿ���ľ�ܸƤӽФ����Ȥ�����
�ޤ���

# ���Τ褦�ʴؿ��ΰ���ɽ�Ϥ��ޤΤȤ�������ޤ��󡥥�������
# �뤷���ʤ��Ǥ��͡�

����ʳ��ˤ�ruby�ε�ǽ��ƤӽФ���ˡ�Ϥ����Ĥ�����ޤ���

2.2.1 ruby�Υץ�������eval����

C����ruby�ε�ǽ��ƤӽФ���äȤ��ñ����ˡ�Ȥ��ơ�ʸ�����
Ϳ����줿ruby�Υץ�������ɾ������ؿ�������ޤ���

  VALUE rb_eval_string(char *str)

����ɾ���ϸ��ߤδĶ��ǹԤ��ޤ����Ĥޤꡤ���ߤΥ��������ѿ�
�ʤɤ�����Ѥ��ޤ���

2.2.2 ID or Symbol

C����ʸ������ͳ������ruby�Υ᥽�åɤ�ƤӽФ����Ȥ�Ǥ���
�����������ˡ�ruby���󥿥ץ꥿��ǥ᥽�åɤ��ѿ�̾����ꤹ��
���˻Ȥ��Ƥ���ID�ˤĤ����������Ƥ����ޤ��礦��

ID�Ȥ��ѿ�̾���᥽�å�̾��ɽ�������Ǥ���ruby����Ǥ�

 :���̻�

�ǥ��������Ǥ��ޤ���C���餳�����������뤿��ˤϴؿ�

  rb_intern(char *name)

��Ȥ��ޤ����ޤ���ʸ���α黻�ҤϤ���ʸ�������ɤ����Τޤޥ���
�ܥ�ˤʤäƤ��ޤ���

2.2.3 Invoke ruby method from C

C����ʸ������ͳ������ruby�Υ᥽�åɤ�ƤӽФ�����ˤϰʲ�
�δؿ���Ȥ��ޤ���

  VALUE rb_funcall(VALUE recv, ID mid, int argc, ...)

���δؿ��ϥ��֥�������recv��mid�ǻ��ꤵ���᥽�åɤ�Ƥӽ�
���ޤ���

2.2.4 �ѿ�/����򻲾�/��������

C����ؿ���Ȥäƻ��ȡ������Ǥ���Τϡ����饹��������󥹥�
���ѿ��Ǥ�������ѿ��ϰ����Τ�Τ�C������ѿ��Ȥ��ƥ�����
���Ǥ��ޤ������������ѿ��򻲾Ȥ�����ˡ�ϸ������Ƥ��ޤ���

���֥������ȤΥ��󥹥����ѿ��򻲾ȡ���������ؿ��ϰʲ�����
��Ǥ���

  VALUE rb_ivar_get(VALUE obj, ID id)
  VALUE rb_ivar_set(VALUE obj, ID id, VALUE val)

id��rb_intern()���������Τ�ȤäƤ���������

���饹����򻲾Ȥ���ˤϰʲ��δؿ���ȤäƤ���������

  VALUE rb_const_get(VALUE obj, ID id)

���饹����򿷤���������뤿��ˤϡ�2.1.3 �������٤ǾҲ�
��Ƥ���ؿ���ȤäƤ���������

3. Informatin sharing between ruby and C

C�����ruby�δ֤Ǿ����ͭ������ˡ�ˤĤ��Ʋ��⤷�ޤ���

3.1 Ruby constant that C���黲�ȤǤ���ruby�����

Following ruby constants can be referred from C.

  TRUE
  FALSE

Boolean values.  FALSE is false in the C also (i.e. 0).

  Qnil

Ruby nil in C scope.

3.2 Global variables shared between C and ruby

C��ruby������ѿ���Ȥäƾ����ͭ�Ǥ��ޤ�����ͭ�Ǥ������
�ѿ��ˤϤ����Ĥ��μ��ब����ޤ������Τʤ��Ǥ�äȤ��ɤ��Ȥ�
���Ȼפ���Τ�rb_define_variable()�Ǥ���

  void rb_define_variable(char *name, VALUE *var)

���δؿ���ruby��C�ȤǶ�ͭ��������ѿ���������ޤ����ѿ�̾��
`$'�ǻϤޤ�ʤ����ˤϼ�ưŪ���ɲä���ޤ��������ѿ����ͤ���
������ȼ�ưŪ��ruby���б������ѿ����ͤ��Ѥ��ޤ���

�ޤ�ruby¦����Ϲ����Ǥ��ʤ��ѿ��⤢��ޤ�������read only��
�ѿ��ϰʲ��δؿ���������ޤ���

  void rb_define_readonly_variable(char *name, VALUE *var)

������ѿ���¾��hook��Ĥ�������ѿ�������Ǥ��ޤ���hook�դ�
������ѿ��ϰʲ��δؿ����Ѥ���������ޤ���hook�դ�����ѿ���
�ͤλ��Ȥ������hook�ǹԤ�ɬ�פ�����ޤ���

  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������ѿ����������
�ؿ�������ޤ���

  void rb_define_virtual_variable(char *name,
				  VALUE (*getter)(), VALUE (*setter)())

���δؿ��ˤ�ä�������줿ruby������ѿ������Ȥ��줿���ˤ�
getter�����ѿ����ͤ����åȤ��줿���ˤ�setter���ƤФ�ޤ���

The prototypes of the getter and setter functions are as following:

  (*getter)(ID id, void *data, struct global_entry* entry);
  (*setter)(VALUE val, ID id, void *data, struct global_entry* entry);

3.3 Encapsulate C data into ruby object

C��������������줿�ǡ���(��¤��)��ruby�Υ��֥������ȤȤ���
��갷��������礬���ꤨ�ޤ������Τ褦�ʾ��ˤϡ�Data�Ȥ���
ruby���֥������Ȥ�C�ι�¤��(�ؤΥݥ���)�򤯤�ळ�Ȥ�ruby
���֥������ȤȤ��Ƽ�갷����褦�ˤʤ�ޤ���

Data���֥������Ȥ��������ƹ�¤�Τ�ruby���֥������Ȥ˥��ץ���
�����뤿��ˤϡ��ʲ��Υޥ�����Ȥ��ޤ���

  Data_Wrap_Struct(class,mark,free,ptr)

���Υޥ���������ͤ��������줿Data���֥������ȤǤ���

class�Ϥ���Data���֥������ȤΥ��饹�Ǥ���ptr�ϥ��ץ��벽����
C�ι�¤�ΤؤΥݥ��󥿤Ǥ���mark�Ϥ��ι�¤�Τ�ruby�Υ��֥���
���Ȥؤλ��Ȥ�������˻Ȥ��ؿ��Ǥ������Τ褦�ʻ��Ȥ�ޤޤʤ�
���ˤ�0����ꤷ�ޤ���

# ���Τ褦�ʻ��Ȥϴ�����ޤ���

free�Ϥ��ι�¤�Τ��⤦���פˤʤä����˸ƤФ��ؿ��Ǥ�������
�ؿ��������١������쥯������ƤФ�ޤ���

C�ι�¤�Τγ�����Data���֥������Ȥ�������Ʊ���˹Ԥ��ޥ�����
���ưʲ��Τ�Τ��󶡤���Ƥ��ޤ���

  Data_Make_Struct(class, type, mark, free, sval)

���Υޥ���������ͤ��������줿Data���֥������ȤǤ���

class, mark, free��Data_Wrap_Struct��Ʊ��Ư���򤷤ޤ���type
�ϳ�����Ƥ�C��¤�Τη��Ǥ���������Ƥ�줿��¤�Τ��ѿ�sval
����������ޤ��������ѿ��η��� (type*) �Ǥ���ɬ�פ�����ޤ���

Data���֥������Ȥ���ݥ��󥿤���Ф��Τϰʲ��Υޥ������Ѥ�
�ޤ���

  Data_Get_Struct(obj, type, sval)

C�ι�¤�ΤؤΥݥ��󥿤��ѿ�sval����������ޤ���

������Data�λȤ����Ϥ���ä�ʬ����ˤ����Τǡ������������
����򻲾Ȥ��Ƥ���������

4��Example - Create dbm module

�����ޤǤ������ǤȤꤢ������ĥ�⥸�塼��Ϻ���Ϥ��Ǥ���
ruby��ext�ǥ��쥯�ȥ�ˤ��Ǥ˴ޤޤ�Ƥ���dbm�⥸�塼������
�����ʳ�Ū���������ޤ���

(1) make the directory

  % mkdir ext/dbm

ruby��Ÿ�������ǥ��쥯�ȥ�β���ext�ǥ��쥯�ȥ����˳�ĥ��
���塼���ѤΥǥ��쥯�ȥ����ޤ���̾����Ŭ��������ǹ�����
����

(2) create MANIFEST file

  % cd ext/dbm
  % touch MANIFEST

��ĥ�⥸�塼��Υǥ��쥯�ȥ�β��ˤ�MANIFEST�Ȥ����ե����뤬
ɬ�פʤΤǡ��Ȥꤢ�������Υե�������äƤ����ޤ�����Ǥ���
�ե�����ˤ�ɬ�פʥե�������������뤳�Ȥˤʤ�ޤ���

MANIFEST�Ȥ����ե�����ϡ�make�λ��˥ǥ��쥯�ȥ꤬��ĥ�⥸�塼
���ޤ�Ǥ��뤫�ɤ���Ƚ�ꤹ�뤿��˻Ȥ���Ƥ��ޤ���

(3) design the library

�ޤ��������ʤ�Ǥ����ɡ��ɤ�������ǽ��¸����뤫�ɤ����ޤ���
�פ���ɬ�פ�����ޤ����ɤ�ʥ��饹��Ĥ��뤫�����Υ��饹�ˤ�
�ɤ�ʥ᥽�åɤ����뤫�����饹���󶡤�������ʤɤˤĤ����߷�
���ޤ���dbm���饹�ˤĤ��Ƥ�ext/dbm.doc�򻲾Ȥ��Ƥ���������

(4) write C code.

��ĥ�⥸�塼�����ΤȤʤ�C����Υ�������񤭤ޤ���C����Υ���
�����ҤȤĤλ��ˤϡ֥⥸�塼��̾.c�פ����֤��ɤ��Ǥ��礦��C
����Υ�������ʣ���ξ��ˤϵդˡ֥⥸�塼��̾.c�פȤ����ե�
����̾���򤱤�ɬ�פ�����ޤ������֥������ȥե�����ȥ⥸�塼
�������������Ū�����������֥⥸�塼��̾.o�פȤ����ե�����
�Ȥ����ͤ��뤫��Ǥ���

ruby�ϳ�ĥ�⥸�塼�������ɤ�����ˡ�Init_�⥸�塼��̾�פ�
�����ؿ���ưŪ�˼¹Ԥ��ޤ���dbm�⥸�塼��ξ���Init_dbm��
�Ǥ������δؿ�����ǥ��饹���⥸�塼�롤�᥽�åɡ�����ʤɤ�
�����Ԥ��ޤ���dbm.c����������Ѥ��ޤ���

--
Init_dbm()
{
    /* DBM���饹��������� */
    cDBM = rb_define_class("DBM", cObject);
    /* DBM��Enumerate�⥸�塼��򥤥󥯥롼�ɤ��� */
    rb_include_module(cDBM, mEnumerable);

    /* DBM���饹�Υ��饹�᥽�å�open(): ������C������Ǽ����� */
    rb_define_singleton_method(cDBM, "open", fdbm_s_open, -1);

    /* DBM���饹�Υ᥽�å�close(): �����Ϥʤ� */
    rb_define_method(cDBM, "close", fdbm_close, 0);
    /* DBM���饹�Υ᥽�å�[]: ������1�� */
    rb_define_method(cDBM, "[]", fdbm_fetch, 1);
		:

    /* DBM�ǡ������Ǽ���륤�󥹥����ѿ�̾�Τ����ID */
    id_dbm = rb_intern("dbm");
}
--

DBM�⥸�塼���dbm�Υǡ������б����륪�֥������Ȥˤʤ�Ϥ���
�����顤C��������dbm��ruby�������˼�����ɬ�פ�����ޤ���


dbm.c�Ǥ�Data_Make_Struct��ʲ��Τ褦�˻ȤäƤ��ޤ���

--
struct dbmdata {
    int  di_size;
    DBM *di_dbm;
};


obj = Data_Make_Struct(class,struct dbmdata,0,free_dbm,dbmp);
--

�����Ǥ�dbmstruct��¤�ΤؤΥݥ��󥿤�Data�˥��ץ��벽���Ƥ�
�ޤ���DBM*��ľ�ܥ��ץ��벽���ʤ��Τ�close()�������ν������
���ƤΤ��ȤǤ���

Data���֥������Ȥ���dbmstruct��¤�ΤΥݥ��󥿤���Ф�����
�˰ʲ��Υޥ�����ȤäƤ��ޤ���

--
#define GetDBM(obj, dbmp) {\
    Data_Get_Struct(obj, struct dbmdata, dbmp);\
    if (dbmp->di_dbm == 0) closed_dbm();\
}
--

����ä�ʣ���ʥޥ����Ǥ������פ����dbmdata��¤�ΤΥݥ���
�μ��Ф��ȡ�close����Ƥ��뤫�ɤ����Υ����å���ޤȤ�Ƥ�
������Ǥ���

DBM���饹�ˤϤ�������᥽�åɤ�����ޤ�����ʬ�ह���3�����
�����μ�����������ޤ����ҤȤĤϰ����ο�������Τ�Τǡ����
���Ƥ�delete�᥽�åɤ�����ޤ���delete�᥽�åɤ�������Ƥ���
fdbm_delete()�Ϥ��Τ褦�ˤʤäƤ��ޤ���

--
static VALUE
fdbm_delete(obj, keystr)
    VALUE obj, keystr;
{
	:
}
--

�����ο�������Υ����פ���1������self����2�����ʹߤ��᥽�å�
�ΰ����Ȥʤ�ޤ���

�����ο�������Τ�Τ�C������Ǽ������Τ�ruby������Ǽ���
���ΤȤ�����ޤ���dbm�⥸�塼�����ǡ�C������Ǽ�������
��DBM�Υ��饹�᥽�åɤǤ���open()�Ǥ��������������Ƥ����
��fdbm_s_open()�Ϥ����ʤäƤ��ޤ���

--
static VALUE
fdbm_s_open(argc, argv, class)
    int argc;
    VALUE *argv;
    VALUE class;
{
	:
    if (rb_scan_args(argc, argv, "11", &file, &vmode) == 1) {
	mode = 0666;		/* default value */
    }
	:
}
--

���Υ����פδؿ�����1������Ϳ����줿�����ο�����2������Ϳ��
��줿���������äƤ�������ˤʤ�ޤ���self����3�����Ȥ���Ϳ
�����ޤ���

���������Ϳ����줿��������Ϥ��뤿��δؿ���open()�Ǥ�Ȥ�
��Ƥ���rb_scan_args()�Ǥ�����3�����˻��ꤷ���ե����ޥåȤ�
��������4�ѿ��ʹߤ˻��ꤷ���ѿ����ͤ��������Ƥ���ޤ�������
�ե����ޥåȤϡ���1ʸ���ܤ���ά�Ǥ��ʤ������ο�����2ʸ���ܤ�
��ά�Ǥ�������ο�����3ʸ���ܤ��б�������̵꤬�����ޤ�ΰ�
�������뤫�ɤ����򼨤�"*"�Ǥ���2ʸ���ܤ�3ʸ���ܤϾ�ά�Ǥ���
����dbm.c����Ǥϡ��ե����ޥåȤ�"11"�Ǥ����顤�����Ϻ���1��
�ǡ�2�Ĥޤǵ������Ȥ�����̣�ˤʤ�ޤ�����ά����Ƥ������
�ѿ����ͤ�nil(C����Υ�٥�Ǥ�Qnil)�ˤʤ�ޤ���

ruby������ǰ������������Τ�indexes������ޤ��������Ϥ�
���Ǥ���

--
static VALUE
fdbm_indexes(obj, args)
    VALUE obj;
    struct RArray *args;
{
	:
}
--

��1������self����2������ruby������Ǥ��������Ǥϥ��㥹�Ȥ�
�餹���� struct RArray* �Ǽ����Ƥ��ޤ�����VALUE�Ǥ�Ʊ������
�Ǥ���

** ���ջ���

ruby�ȶ�ͭ�Ϥ��ʤ���ruby�Υ��֥������Ȥ��Ǽ�����ǽ���Τ���
C������ѿ��ϰʲ��δؿ���Ȥä�ruby���󥿥ץ꥿���ѿ���¸��
�򶵤��Ƥ����Ƥ����������Ǥʤ���GC�ǥȥ�֥�򵯤����ޤ���

  void rb_global_variable(VALUE *var)

(5) prepare extconf.rb

�⤷�ǥ��쥯�ȥ�ˡ�extconf.rb�פȤ����ե����뤬¸�ߤ���С�
make���˼¹Ԥ���ޤ����ʤ����Ŭ����Makefile����������ޤ���

extconf.rb�ϥ⥸�塼��Υ���ѥ����ɬ�פʾ��Υ����å��ʤ�
��Ԥ����Ȥ���Ū�Ǥ���extconf.rb����Ǥϰʲ���ruby�ؿ���Ȥ�
���Ȥ�����ޤ���

  have_library(lib, func): �饤�֥���¸�ߥ����å�
  have_func(func): �ؿ���¸�ߥ����å�
  have_header(header): �إå��ե������¸�ߥ����å�
  create_makefile(target): Makefile������

�ʲ����ѿ���Ȥ����Ȥ��Ǥ��ޤ���

  $CFLAGS: ����ѥ�������ɲ�Ū�˻��ꤹ��ե饰(-I�ʤ�)
  $LDFLAGS: ��󥯻����ɲ�Ū�˻��ꤹ��ե饰(-L�ʤ�)

�⥸�塼��򥳥�ѥ��뤹���郎·��ʤ������Υ⥸�塼��ϥ�
��ѥ��뤷�ʤ����ˤ�create_makefile��ƤФʤ����Makefile��
�������줺������ѥ����Ԥ��ޤ���

(6) prepare depend (optional)

�⤷���ǥ��쥯�ȥ��depend�Ȥ����ե����뤬¸�ߤ���С�
Makefile����¸�ط�������å����Ƥ���ޤ���

 % gcc -MM *.c > depend

�ʤɤǺ�뤳�Ȥ�����ޤ������ä�»��̵���Ǥ��礦��

(7) MANIFEST�ե�����˥ե�����̾�������

  % ls > MANIFEST
  % vi MANIFEST

*.o, *~�ʤ���ɬ�פʥե�����ʳ���MANIFEST���ɲä��Ƥ����ޤ���
make���ˤ�MANIFEST�����Ƥϻ��Ȥ��ޤ���Τǡ����ΤޤޤǤ�����
�ϵ����ޤ��󤬡��ѥå������󥰤λ��˻��Ȥ��뤳�Ȥ�����Τȡ�
ɬ�פʥե��������̤Ǥ���Τǡ��Ѱդ��Ƥ����������ɤ��Ǥ���
����

(8) make

ruby�Υǥ��쥯�ȥ��make��¹Ԥ����Makefile����������make��
ɬ�פˤ�äƤϤ��Υ⥸�塼���ruby�ؤΥ�󥯤ޤǼ�ưŪ�˼¹�
���Ƥ���ޤ���extconf.rb��񤭴�����ʤɤ���Makefile�κ�����
��ɬ�פʻ��Ϥޤ�ruby�ǥ��쥯�ȥ��make���Ƥ���������

(9) debug

�ޤ����ǥХå����ʤ���ư���ʤ��Ǥ��礦�͡�ext/Setup�˥ǥ���
���ȥ�̾��񤯤���Ū�˥�󥯤���ΤǥǥХå����Ȥ���褦�ˤ�
��ޤ�������ʬ����ѥ��뤬�٤��ʤ�ޤ����ɡ�

(10) done, now you have the extension module

��Ϥ��ä���Ȥ��ʤꡤ������������ʤꡤ���ʤꡤ����ͳ�ˤ�
�Ȥ�����������ruby�κ�Ԥϳ�ĥ�⥸�塼��˴ؤ��ư��ڤθ�����
��ĥ���ޤ���

Appendix A. ruby�Υ����������ɤ�ʬ��

ruby�Υ������Ϥ����Ĥ���ʬ�ह�뤳�Ȥ�����ޤ������Τ�������
���饤�֥�����ʬ�ϴ���Ū�˳�ĥ�⥸�塼���Ʊ��������ˤʤ�
�Ƥ��ޤ��������Υ������Ϻ��ޤǤ������ǤۤȤ������Ǥ����
�פ��ޤ���

coore ruby language

  class.c
  error.c
  eval.c
  gc.c
  object.c
  parse.y
  variable.c

utility functions

  dln.c
  fnmatch.c
  glob.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
  math.c
  numeric.c
  pack.c
  process.c
  random.c
  range.c
  re.c
  signal.c
  sprintf.c
  string.c
  struct.c
  time.c

Appendix B. ��ĥ�Ѵؿ���ե����

C���줫��ruby�ε�ǽ�����Ѥ���API�ϰʲ����̤�Ǥ��롥

** ��

 VALUE

ruby���֥������Ȥ�ɽ�����뷿��ɬ�פ˱����ƥ��㥹�Ȥ����Ѥ��롥
�Ȥ߹��߷���ɽ������C�η���ruby.h�˵��Ҥ��Ƥ���R�ǻϤޤ빽¤
�ΤǤ��롥VALUE���򤳤��˥��㥹�Ȥ��뤿���R�ǻϤޤ빽¤��
̾��������ʸ���ˤ���̾���Υޥ������Ѱդ���Ƥ��롥

** Variables and constants

 Qnil

const: nil object

 TRUE

const: TRUE object(default true value)

 FALSE

const: FALSE object

** C�ǡ����Υ��ץ��벽

 Data_Wrap_Struct(VALUE class, void (*mark)(), void (*free)(), void *sval)

C��Ǥ�դΥݥ��󥿤򥫥ץ��벽����ruby���֥������Ȥ��֤�����
�Υݥ��󥿤�ruby���饢����������ʤ��ʤä�����free�ǻ��ꤷ��
�ؿ����ƤФ�롥�ޤ������Υݥ��󥿤λؤ��ǡ�����¾��ruby����
�������Ȥ�ؤ��Ƥ����硤mark�˻��ꤹ��ؿ��ǥޡ�������ɬ��
�����롥

 Data_Make_Struct(class, type, mark, free, sval)

type���Υ����malloc�����ѿ�sval�����������塤����򥫥ץ�
�벽�����ǡ������֤��ޥ�����

 Data_Get_Struct(data, type, sval)

data����type���Υݥ��󥿤���Ф��ѿ�sval����������ޥ�����

** ���饹/�⥸�塼�����

 VALUE rb_define_class(char *name, VALUE super)

super�Υ��֥��饹�Ȥ��ƿ�����ruby���饹��������롥

 VALUE rb_define_class_under(VALUE module, char *name, VALUE super)

super�Υ��֥��饹�Ȥ��ƿ�����ruby���饹���������module����
���Ȥ���������롥

 VALUE rb_define_module(char *name)

������ruby�⥸�塼���������롥

 VALUE rb_define_module_under(VALUE module, char *name, VALUE super)

������ruby�⥸�塼����������module������Ȥ���������롥

 void rb_include_module(VALUE class, VALUE module)

�⥸�塼��򥤥󥯥롼�ɤ��롥class�����Ǥ�module�򥤥󥯥롼
�ɤ��Ƥ�����ˤϲ��⤷�ʤ�(¿�ť��󥯥롼�ɤζػ�)��

 void rb_extend_object(VALUE object, VALUE module)

���֥������Ȥ�⥸�塼��(���������Ƥ���᥽�å�)�dz�ĥ���롥

** ����ѿ����

 void rb_define_variable(char *name, VALUE *var)

ruby��C�ȤǶ�ͭ���륰�����Х��ѿ���������롥�ѿ�̾��`$'�ǻ�
�ޤ�ʤ����ˤϼ�ưŪ���ɲä���롥name�Ȥ���ruby�μ��̻ҤȤ�
�Ƶ�����ʤ�ʸ��(�㤨��` ')��ޤ���ˤ�ruby�ץ�����फ��
�ϸ����ʤ��ʤ롥

 void rb_define_readonly_variable(char *name, VALUE *var)

ruby��C�ȤǶ�ͭ����read only�Υ������Х��ѿ���������롥read
only�Ǥ��뤳�Ȱʳ���rb_define_variable()��Ʊ����

 void rb_define_virtual_variable(char *name,
				VALUE (*getter)(), VALUE (*setter)())

�ؿ��ˤ�äƼ¸������ruby�ѿ���������롥�ѿ������Ȥ��줿��
�ˤ�getter�����ѿ����ͤ����åȤ��줿���ˤ�setter���ƤФ�롥

 void rb_define_hooked_variable(char *name, VALUE *var,
				VALUE (*getter)(), VALUE (*setter)())

�ؿ��ˤ�ä�hook�ΤĤ���줿�������Х��ѿ���������롥�ѿ���
���Ȥ��줿���ˤ�getter�����ؿ����ͤ����åȤ��줿���ˤ�setter
���ƤФ�롥getter��setter��0����ꤷ�����ˤ�hook����ꤷ��
���Τ�Ʊ�����ˤʤ롥

 void rb_global_variable(VALUE *var)

GC�Τ��ᡤruby�ץ�����फ��ϥ�����������ʤ���, ruby���֥���
���Ȥ�ޤ�����ѿ���ޡ������롥

** ���饹���

 void rb_define_const(VALUE class, char *name, VALUE val)

���饹�����������롥

 void rb_define_global_const(char *name, VALUE val)

��������������롥

     rb_define_const(cKernal, name, val)

��Ʊ����̣��

** �᥽�å����

 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������)�Ȥ�����
����Ϳ�����롥

 rb_define_private_method(VALUE class, char *name, VALUE (*func)(), int argc)

private�᥽�åɤ�������롥������rb_define_method()��Ʊ����

 rb_define_singleton_method(VALUE class, char *name, VALUE (*func)(), int argc)

�ðۥ᥽�åɤ�������롥������rb_define_method()��Ʊ����

 rb_scan_args(int atgc, VALUE *argv, char *fmt, ...)

argc,argv������Ϳ����줿������ʬ�򤹤롥fmt��ɬ�ܰ����ο�, 
�ղð����ο�, �Ĥ�ΰ��������뤫����ꤹ��ʸ�����, "������
��*"�Ȥ��������Ǥ��롥 2 ���ܤο�����"*"�Ϥ��줾���ά��ǽ��
���롥ɬ�ܰ�������Ĥ�ʤ�����0����ꤹ�롥��3�����ʹߤ���
���ؤΥݥ��󥿤�, �����������Ǥ������ѿ��˳�Ǽ����롥�ղð�
�����б����������Ϳ�����Ƥ��ʤ������ѿ���Qnil����������
�롥

** ruby�᥽�åɸƤӽФ�

 VALUE rb_funcall(VALUE recv, ID mid, int narg, ...)

�᥽�åɸƤӽФ���ʸ���󤫤�mid�����뤿��ˤ�rb_intern()��Ȥ���

 VALUE rb_funcall2(VALUE recv, ID mid, int argc, VALUE *argv)

�᥽�åɸƤӽФ���������argc,argv�������Ϥ���

 VALUE rb_eval_string(char *str)

ʸ�����ruby�ȥ�����ץȤ��ƥ���ѥ��롦�¹Ԥ��롥

 ID rb_intern(char *name)

ʸ������б�����ID���֤���

 char *rb_id2name(ID id)

ID���б�����ʸ������֤�(�ǥХå���)��

 char *rb_class2name(VALUE class)

class��̾�����֤�(�ǥХå���)��class��̾��������ʤ����ˤ�, 
������̤ä�̾������ĥ��饹��̾�����֤���

** ���󥹥����ѿ�

 VALUE rb_iv_get(VALUE obj, char *name)

obj�Υ��󥹥����ѿ����ͤ����롥`@'�ǻϤޤ�ʤ����󥹥���
�ѿ��� ruby�ץ�����फ�饢�������Ǥ��ʤ��ֱ��줿�ץ��󥹥�
���ѿ��ˤʤ롥

 VALUE rb_iv_set(VALUE obj, char *name, VALUE val)

obj�Υ��󥹥����ѿ���val�˥��åȤ��롥

** ���湽¤

 VALUE rb_iterate(VALUE (*func1)(), void *arg1, VALUE (*func2)(), void *arg2)

func2��֥��å��Ȥ������ꤷ, func1�򥤥ƥ졼���Ȥ��ƸƤ֡� 
func1�ˤ� arg1�������Ȥ����Ϥ���, func2�ˤ���1�����˥��ƥ졼
������Ϳ����줿��, ��2������arg2���Ϥ���롥
 
 VALUE rb_yield(VALUE val)

val���ͤȤ��ƥ��ƥ졼���֥��å���ƤӽФ���

 VALUE rb_rescue(VALUE (*func1)(), void *arg1, VALUE (*func2)(), void *arg2)

�ؿ�func1��arg1������˸ƤӽФ���func1�μ¹�����㳰��ȯ����
�����ˤ� func2��arg2������Ȥ��ƸƤ֡�����ͤ��㳰��ȯ������
���ä�����func1�������, �㳰��ȯ���������ˤ�func2������ͤ�
���롥

 VALUE rb_ensure(VALUE (*func1)(), void *arg1, void (*func2)(), void *arg2)

�ؿ�func1��arg1������Ȥ��Ƽ¹Ԥ�, �¹Խ�λ��(���Ȥ��㳰��ȯ
�����Ƥ�) func2��arg2������Ȥ��Ƽ¹Ԥ��롥����ͤ�func1����
���ͤǤ���(�㳰��ȯ�������������ʤ�)��

** �㳰�����顼

 void Warning(char *fmt, ...)

verbose����ɸ�२�顼���Ϥ˷ٹ�����ɽ�����롥������printf()��Ʊ����

 void Fail(char *fmt, ...)

�㳰��ȯ�������롥������printf()��Ʊ����

 void Fatal(char *fmt, ...)

��̿Ū�㳰��ȯ�������롥�̾���㳰�����ϹԤʤ�줺, ���󥿡�
�ץ꥿����λ����(������ensure�ǻ��ꤵ�줿�����ɤϽ�λ���˼�
�Ԥ����)��

 void Bug(char *fmt, ...)

���󥿡��ץ꥿�ʤɥץ������ΥХ��Ǥ���ȯ������Ϥ��Τʤ���
���λ��Ƥ֡����󥿡��ץ꥿�ϥ�������פ�ľ���˽�λ���롥�㳰
�����ϰ��ڹԤʤ��ʤ���

** ruby�ν�������¹�

ruby�򥢥ץꥱ����������������ˤϰʲ��Υ��󥿥ե�����
��Ȥ����̾�γ�ĥ�⥸�塼��ˤ�ɬ�פʤ���

 void ruby_init(int argc, char **argv, char **envp)

ruby���󥿥ץ꥿�ν������Ԥʤ���

 void ruby_run()

ruby���󥿥ץ꥿��¹Ԥ��롥

 void ruby_script(char *name)

ruby�Υ�����ץ�̾($0)�����ꤹ�롥

Appendix B. extconf.rb�ǻȤ���ؿ�����

extconf.rb����Ǥ����Ѳ�ǽ�ʥ���ѥ���������å��δؿ��ϰ�
�����̤�Ǥ��롥

 have_library(lib, func)

�ؿ�func��������Ƥ���饤�֥��lib��¸�ߤ�����å����롥��
���֥�꤬¸�ߤ������TRUE���֤���

 have_func(func)

�ؿ�func��¸�ߤ�����å����롥func��ɸ��Ǥϥ�󥯤���ʤ���
���֥����Τ�ΤǤ�����ˤ����have_library�Ǥ��Υ饤�֥��
������å����Ƥ��������ؿ���¸�ߤ����TRUE���֤���

 have_header(header)

�إå��ե������¸�ߤ�����å����롥�إå��ե����뤬¸�ߤ���
��TRUE���֤���

 create_makefile(target)

��ĥ�⥸�塼���Ѥ�Makefile���������롥���δؿ���ƤФʤ����
���Υ⥸�塼��ϥ���ѥ��뤵��ʤ���target�ϥ⥸�塼��̾��ɽ
����

/*
 * Local variables:
 * fill-column: 60
 * end:
 */