ruby2d 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +5 -5
  2. data/assets/README.md +8 -0
  3. data/assets/ios/Assets.xcassets/AppIcon.appiconset/Contents.json +98 -0
  4. data/assets/ios/Assets.xcassets/Contents.json +6 -0
  5. data/assets/ios/Base.lproj/LaunchScreen.storyboard +27 -0
  6. data/assets/ios/Info.plist +43 -0
  7. data/assets/ios/MRuby.framework/Headers/mrbconf.h +145 -0
  8. data/assets/ios/MRuby.framework/Headers/mruby.h +1279 -0
  9. data/assets/ios/MRuby.framework/Headers/mruby/array.h +279 -0
  10. data/assets/ios/MRuby.framework/Headers/mruby/boxing_nan.h +102 -0
  11. data/assets/ios/MRuby.framework/Headers/mruby/boxing_no.h +56 -0
  12. data/assets/ios/MRuby.framework/Headers/mruby/boxing_word.h +136 -0
  13. data/assets/ios/MRuby.framework/Headers/mruby/class.h +94 -0
  14. data/assets/ios/MRuby.framework/Headers/mruby/common.h +72 -0
  15. data/assets/ios/MRuby.framework/Headers/mruby/compile.h +194 -0
  16. data/assets/ios/MRuby.framework/Headers/mruby/data.h +75 -0
  17. data/assets/ios/MRuby.framework/Headers/mruby/debug.h +66 -0
  18. data/assets/ios/MRuby.framework/Headers/mruby/dump.h +196 -0
  19. data/assets/ios/MRuby.framework/Headers/mruby/error.h +75 -0
  20. data/assets/ios/MRuby.framework/Headers/mruby/gc.h +91 -0
  21. data/assets/ios/MRuby.framework/Headers/mruby/hash.h +182 -0
  22. data/assets/ios/MRuby.framework/Headers/mruby/irep.h +62 -0
  23. data/assets/ios/MRuby.framework/Headers/mruby/istruct.h +47 -0
  24. data/assets/ios/MRuby.framework/Headers/mruby/khash.h +274 -0
  25. data/assets/ios/MRuby.framework/Headers/mruby/numeric.h +161 -0
  26. data/assets/ios/MRuby.framework/Headers/mruby/object.h +45 -0
  27. data/assets/ios/MRuby.framework/Headers/mruby/opcode.h +161 -0
  28. data/assets/ios/MRuby.framework/Headers/mruby/proc.h +131 -0
  29. data/assets/ios/MRuby.framework/Headers/mruby/range.h +49 -0
  30. data/assets/ios/MRuby.framework/Headers/mruby/re.h +16 -0
  31. data/assets/ios/MRuby.framework/Headers/mruby/string.h +440 -0
  32. data/assets/ios/MRuby.framework/Headers/mruby/throw.h +55 -0
  33. data/assets/ios/MRuby.framework/Headers/mruby/value.h +309 -0
  34. data/assets/ios/MRuby.framework/Headers/mruby/variable.h +138 -0
  35. data/assets/ios/MRuby.framework/Headers/mruby/version.h +110 -0
  36. data/assets/ios/MRuby.framework/Info.plist +20 -0
  37. data/assets/ios/MRuby.framework/MRuby +0 -0
  38. data/assets/ios/MyApp.xcodeproj/project.pbxproj +362 -0
  39. data/assets/ios/MyApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  40. data/assets/ios/MyApp.xcodeproj/project.xcworkspace/xcshareddata/MyApp.xcscmblueprint +30 -0
  41. data/assets/ios/MyApp.xcodeproj/project.xcworkspace/xcuserdata/Tom.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  42. data/assets/ios/MyApp.xcodeproj/xcuserdata/Tom.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  43. data/assets/ios/main.c +1 -0
  44. data/assets/opal.js +8434 -6329
  45. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Content.imageset/Contents.json +12 -0
  46. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Contents.json +6 -0
  47. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Contents.json +17 -0
  48. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Content.imageset/Contents.json +12 -0
  49. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Contents.json +6 -0
  50. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json +12 -0
  51. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Contents.json +6 -0
  52. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Content.imageset/Contents.json +12 -0
  53. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Contents.json +6 -0
  54. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Contents.json +17 -0
  55. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Content.imageset/Contents.json +12 -0
  56. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Contents.json +6 -0
  57. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json +12 -0
  58. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Contents.json +6 -0
  59. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Contents.json +32 -0
  60. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Top Shelf Image Wide.imageset/Contents.json +12 -0
  61. data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Top Shelf Image.imageset/Contents.json +12 -0
  62. data/assets/tvos/Assets.xcassets/Contents.json +6 -0
  63. data/assets/tvos/Assets.xcassets/LaunchImage.launchimage/Contents.json +15 -0
  64. data/assets/tvos/Info.plist +30 -0
  65. data/assets/tvos/MRuby.framework/Headers/mrbconf.h +145 -0
  66. data/assets/tvos/MRuby.framework/Headers/mruby.h +1279 -0
  67. data/assets/tvos/MRuby.framework/Headers/mruby/array.h +279 -0
  68. data/assets/tvos/MRuby.framework/Headers/mruby/boxing_nan.h +102 -0
  69. data/assets/tvos/MRuby.framework/Headers/mruby/boxing_no.h +56 -0
  70. data/assets/tvos/MRuby.framework/Headers/mruby/boxing_word.h +136 -0
  71. data/assets/tvos/MRuby.framework/Headers/mruby/class.h +94 -0
  72. data/assets/tvos/MRuby.framework/Headers/mruby/common.h +72 -0
  73. data/assets/tvos/MRuby.framework/Headers/mruby/compile.h +194 -0
  74. data/assets/tvos/MRuby.framework/Headers/mruby/data.h +75 -0
  75. data/assets/tvos/MRuby.framework/Headers/mruby/debug.h +66 -0
  76. data/assets/tvos/MRuby.framework/Headers/mruby/dump.h +196 -0
  77. data/assets/tvos/MRuby.framework/Headers/mruby/error.h +75 -0
  78. data/assets/tvos/MRuby.framework/Headers/mruby/gc.h +91 -0
  79. data/assets/tvos/MRuby.framework/Headers/mruby/hash.h +182 -0
  80. data/assets/tvos/MRuby.framework/Headers/mruby/irep.h +62 -0
  81. data/assets/tvos/MRuby.framework/Headers/mruby/istruct.h +47 -0
  82. data/assets/tvos/MRuby.framework/Headers/mruby/khash.h +274 -0
  83. data/assets/tvos/MRuby.framework/Headers/mruby/numeric.h +161 -0
  84. data/assets/tvos/MRuby.framework/Headers/mruby/object.h +45 -0
  85. data/assets/tvos/MRuby.framework/Headers/mruby/opcode.h +161 -0
  86. data/assets/tvos/MRuby.framework/Headers/mruby/proc.h +131 -0
  87. data/assets/tvos/MRuby.framework/Headers/mruby/range.h +49 -0
  88. data/assets/tvos/MRuby.framework/Headers/mruby/re.h +16 -0
  89. data/assets/tvos/MRuby.framework/Headers/mruby/string.h +440 -0
  90. data/assets/tvos/MRuby.framework/Headers/mruby/throw.h +55 -0
  91. data/assets/tvos/MRuby.framework/Headers/mruby/value.h +309 -0
  92. data/assets/tvos/MRuby.framework/Headers/mruby/variable.h +138 -0
  93. data/assets/tvos/MRuby.framework/Headers/mruby/version.h +110 -0
  94. data/assets/tvos/MRuby.framework/Info.plist +20 -0
  95. data/assets/tvos/MRuby.framework/MRuby +0 -0
  96. data/assets/tvos/MyApp.xcodeproj/project.pbxproj +344 -0
  97. data/assets/tvos/MyApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  98. data/assets/tvos/MyApp.xcodeproj/project.xcworkspace/xcshareddata/MyApp.xcscmblueprint +30 -0
  99. data/assets/tvos/main.c +1 -0
  100. data/bin/ruby2d +219 -64
  101. data/ext/ruby2d/extconf.rb +1 -1
  102. data/ext/ruby2d/ruby2d.c +117 -19
  103. data/lib/ruby2d/color.rb +1 -1
  104. data/lib/ruby2d/version.rb +1 -1
  105. data/lib/ruby2d/window.rb +16 -10
  106. metadata +102 -5
@@ -0,0 +1,45 @@
1
+ /*
2
+ ** mruby/object.h - mruby object definition
3
+ **
4
+ ** See Copyright Notice in mruby.h
5
+ */
6
+
7
+ #ifndef MRUBY_OBJECT_H
8
+ #define MRUBY_OBJECT_H
9
+
10
+ #define MRB_OBJECT_HEADER \
11
+ enum mrb_vtype tt:8;\
12
+ uint32_t color:3;\
13
+ uint32_t flags:21;\
14
+ struct RClass *c;\
15
+ struct RBasic *gcnext
16
+
17
+ #define MRB_FLAG_TEST(obj, flag) ((obj)->flags & flag)
18
+
19
+
20
+ struct RBasic {
21
+ MRB_OBJECT_HEADER;
22
+ };
23
+ #define mrb_basic_ptr(v) ((struct RBasic*)(mrb_ptr(v)))
24
+
25
+ /* flags bits >= 18 is reserved */
26
+ #define MRB_FLAG_IS_FROZEN (1 << 18)
27
+ #define MRB_FROZEN_P(o) ((o)->flags & MRB_FLAG_IS_FROZEN)
28
+ #define MRB_SET_FROZEN_FLAG(o) ((o)->flags |= MRB_FLAG_IS_FROZEN)
29
+ #define MRB_UNSET_FROZEN_FLAG(o) ((o)->flags &= ~MRB_FLAG_IS_FROZEN)
30
+
31
+ struct RObject {
32
+ MRB_OBJECT_HEADER;
33
+ struct iv_tbl *iv;
34
+ };
35
+ #define mrb_obj_ptr(v) ((struct RObject*)(mrb_ptr(v)))
36
+
37
+ #define mrb_immediate_p(x) (mrb_type(x) < MRB_TT_HAS_BASIC)
38
+ #define mrb_special_const_p(x) mrb_immediate_p(x)
39
+
40
+ struct RFiber {
41
+ MRB_OBJECT_HEADER;
42
+ struct mrb_context *cxt;
43
+ };
44
+
45
+ #endif /* MRUBY_OBJECT_H */
@@ -0,0 +1,161 @@
1
+ /*
2
+ ** mruby/opcode.h - RiteVM operation codes
3
+ **
4
+ ** See Copyright Notice in mruby.h
5
+ */
6
+
7
+ #ifndef MRUBY_OPCODE_H
8
+ #define MRUBY_OPCODE_H
9
+
10
+ #define MAXARG_Bx (0xffff)
11
+ #define MAXARG_sBx (MAXARG_Bx>>1) /* 'sBx' is signed */
12
+
13
+ /* instructions: packed 32 bit */
14
+ /* ------------------------------- */
15
+ /* A:B:C:OP = 9: 9: 7: 7 */
16
+ /* A:Bx:OP = 9:16: 7 */
17
+ /* Ax:OP = 25: 7 */
18
+ /* A:Bz:Cz:OP = 9:14: 2: 7 */
19
+
20
+ #define GET_OPCODE(i) ((int)(((mrb_code)(i)) & 0x7f))
21
+ #define GETARG_A(i) ((int)((((mrb_code)(i)) >> 23) & 0x1ff))
22
+ #define GETARG_B(i) ((int)((((mrb_code)(i)) >> 14) & 0x1ff))
23
+ #define GETARG_C(i) ((int)((((mrb_code)(i)) >> 7) & 0x7f))
24
+ #define GETARG_Bx(i) ((int)((((mrb_code)(i)) >> 7) & 0xffff))
25
+ #define GETARG_sBx(i) ((int)(GETARG_Bx(i)-MAXARG_sBx))
26
+ #define GETARG_Ax(i) ((int32_t)((((mrb_code)(i)) >> 7) & 0x1ffffff))
27
+ #define GETARG_UNPACK_b(i,n1,n2) ((int)((((mrb_code)(i)) >> (7+(n2))) & (((1<<(n1))-1))))
28
+ #define GETARG_UNPACK_c(i,n1,n2) ((int)((((mrb_code)(i)) >> 7) & (((1<<(n2))-1))))
29
+ #define GETARG_b(i) GETARG_UNPACK_b(i,14,2)
30
+ #define GETARG_c(i) GETARG_UNPACK_c(i,14,2)
31
+
32
+ #define MKOPCODE(op) ((op) & 0x7f)
33
+ #define MKARG_A(c) ((mrb_code)((c) & 0x1ff) << 23)
34
+ #define MKARG_B(c) ((mrb_code)((c) & 0x1ff) << 14)
35
+ #define MKARG_C(c) (((c) & 0x7f) << 7)
36
+ #define MKARG_Bx(v) ((mrb_code)((v) & 0xffff) << 7)
37
+ #define MKARG_sBx(v) MKARG_Bx((v)+MAXARG_sBx)
38
+ #define MKARG_Ax(v) ((mrb_code)((v) & 0x1ffffff) << 7)
39
+ #define MKARG_PACK(b,n1,c,n2) ((((b) & ((1<<n1)-1)) << (7+n2))|(((c) & ((1<<n2)-1)) << 7))
40
+ #define MKARG_bc(b,c) MKARG_PACK(b,14,c,2)
41
+
42
+ #define MKOP_A(op,a) (MKOPCODE(op)|MKARG_A(a))
43
+ #define MKOP_AB(op,a,b) (MKOP_A(op,a)|MKARG_B(b))
44
+ #define MKOP_ABC(op,a,b,c) (MKOP_AB(op,a,b)|MKARG_C(c))
45
+ #define MKOP_ABx(op,a,bx) (MKOP_A(op,a)|MKARG_Bx(bx))
46
+ #define MKOP_Bx(op,bx) (MKOPCODE(op)|MKARG_Bx(bx))
47
+ #define MKOP_sBx(op,sbx) (MKOPCODE(op)|MKARG_sBx(sbx))
48
+ #define MKOP_AsBx(op,a,sbx) (MKOP_A(op,a)|MKARG_sBx(sbx))
49
+ #define MKOP_Ax(op,ax) (MKOPCODE(op)|MKARG_Ax(ax))
50
+ #define MKOP_Abc(op,a,b,c) (MKOP_A(op,a)|MKARG_bc(b,c))
51
+
52
+ enum {
53
+ /*-----------------------------------------------------------------------
54
+ operation code operand description
55
+ ------------------------------------------------------------------------*/
56
+ OP_NOP=0,/* */
57
+ OP_MOVE,/* A B R(A) := R(B) */
58
+ OP_LOADL,/* A Bx R(A) := Pool(Bx) */
59
+ OP_LOADI,/* A sBx R(A) := sBx */
60
+ OP_LOADSYM,/* A Bx R(A) := Syms(Bx) */
61
+ OP_LOADNIL,/* A R(A) := nil */
62
+ OP_LOADSELF,/* A R(A) := self */
63
+ OP_LOADT,/* A R(A) := true */
64
+ OP_LOADF,/* A R(A) := false */
65
+
66
+ OP_GETGLOBAL,/* A Bx R(A) := getglobal(Syms(Bx)) */
67
+ OP_SETGLOBAL,/* A Bx setglobal(Syms(Bx), R(A)) */
68
+ OP_GETSPECIAL,/*A Bx R(A) := Special[Bx] */
69
+ OP_SETSPECIAL,/*A Bx Special[Bx] := R(A) */
70
+ OP_GETIV,/* A Bx R(A) := ivget(Syms(Bx)) */
71
+ OP_SETIV,/* A Bx ivset(Syms(Bx),R(A)) */
72
+ OP_GETCV,/* A Bx R(A) := cvget(Syms(Bx)) */
73
+ OP_SETCV,/* A Bx cvset(Syms(Bx),R(A)) */
74
+ OP_GETCONST,/* A Bx R(A) := constget(Syms(Bx)) */
75
+ OP_SETCONST,/* A Bx constset(Syms(Bx),R(A)) */
76
+ OP_GETMCNST,/* A Bx R(A) := R(A)::Syms(Bx) */
77
+ OP_SETMCNST,/* A Bx R(A+1)::Syms(Bx) := R(A) */
78
+ OP_GETUPVAR,/* A B C R(A) := uvget(B,C) */
79
+ OP_SETUPVAR,/* A B C uvset(B,C,R(A)) */
80
+
81
+ OP_JMP,/* sBx pc+=sBx */
82
+ OP_JMPIF,/* A sBx if R(A) pc+=sBx */
83
+ OP_JMPNOT,/* A sBx if !R(A) pc+=sBx */
84
+ OP_ONERR,/* sBx rescue_push(pc+sBx) */
85
+ OP_RESCUE,/* A B C if A (if C exc=R(A) else R(A) := exc);
86
+ if B R(B) := exc.isa?(R(B)); clear(exc) */
87
+ OP_POPERR,/* A A.times{rescue_pop()} */
88
+ OP_RAISE,/* A raise(R(A)) */
89
+ OP_EPUSH,/* Bx ensure_push(SEQ[Bx]) */
90
+ OP_EPOP,/* A A.times{ensure_pop().call} */
91
+
92
+ OP_SEND,/* A B C R(A) := call(R(A),Syms(B),R(A+1),...,R(A+C)) */
93
+ OP_SENDB,/* A B C R(A) := call(R(A),Syms(B),R(A+1),...,R(A+C),&R(A+C+1))*/
94
+ OP_FSEND,/* A B C R(A) := fcall(R(A),Syms(B),R(A+1),...,R(A+C-1)) */
95
+ OP_CALL,/* A R(A) := self.call(frame.argc, frame.argv) */
96
+ OP_SUPER,/* A C R(A) := super(R(A+1),... ,R(A+C+1)) */
97
+ OP_ARGARY,/* A Bx R(A) := argument array (16=6:1:5:4) */
98
+ OP_ENTER,/* Ax arg setup according to flags (23=5:5:1:5:5:1:1) */
99
+ OP_KARG,/* A B C R(A) := kdict[Syms(B)]; if C kdict.rm(Syms(B)) */
100
+ OP_KDICT,/* A C R(A) := kdict */
101
+
102
+ OP_RETURN,/* A B return R(A) (B=normal,in-block return/break) */
103
+ OP_TAILCALL,/* A B C return call(R(A),Syms(B),*R(C)) */
104
+ OP_BLKPUSH,/* A Bx R(A) := block (16=6:1:5:4) */
105
+
106
+ OP_ADD,/* A B C R(A) := R(A)+R(A+1) (Syms[B]=:+,C=1) */
107
+ OP_ADDI,/* A B C R(A) := R(A)+C (Syms[B]=:+) */
108
+ OP_SUB,/* A B C R(A) := R(A)-R(A+1) (Syms[B]=:-,C=1) */
109
+ OP_SUBI,/* A B C R(A) := R(A)-C (Syms[B]=:-) */
110
+ OP_MUL,/* A B C R(A) := R(A)*R(A+1) (Syms[B]=:*,C=1) */
111
+ OP_DIV,/* A B C R(A) := R(A)/R(A+1) (Syms[B]=:/,C=1) */
112
+ OP_EQ,/* A B C R(A) := R(A)==R(A+1) (Syms[B]=:==,C=1) */
113
+ OP_LT,/* A B C R(A) := R(A)<R(A+1) (Syms[B]=:<,C=1) */
114
+ OP_LE,/* A B C R(A) := R(A)<=R(A+1) (Syms[B]=:<=,C=1) */
115
+ OP_GT,/* A B C R(A) := R(A)>R(A+1) (Syms[B]=:>,C=1) */
116
+ OP_GE,/* A B C R(A) := R(A)>=R(A+1) (Syms[B]=:>=,C=1) */
117
+
118
+ OP_ARRAY,/* A B C R(A) := ary_new(R(B),R(B+1)..R(B+C)) */
119
+ OP_ARYCAT,/* A B ary_cat(R(A),R(B)) */
120
+ OP_ARYPUSH,/* A B ary_push(R(A),R(B)) */
121
+ OP_AREF,/* A B C R(A) := R(B)[C] */
122
+ OP_ASET,/* A B C R(B)[C] := R(A) */
123
+ OP_APOST,/* A B C *R(A),R(A+1)..R(A+C) := R(A) */
124
+
125
+ OP_STRING,/* A Bx R(A) := str_dup(Lit(Bx)) */
126
+ OP_STRCAT,/* A B str_cat(R(A),R(B)) */
127
+
128
+ OP_HASH,/* A B C R(A) := hash_new(R(B),R(B+1)..R(B+C)) */
129
+ OP_LAMBDA,/* A Bz Cz R(A) := lambda(SEQ[Bz],Cz) */
130
+ OP_RANGE,/* A B C R(A) := range_new(R(B),R(B+1),C) */
131
+
132
+ OP_OCLASS,/* A R(A) := ::Object */
133
+ OP_CLASS,/* A B R(A) := newclass(R(A),Syms(B),R(A+1)) */
134
+ OP_MODULE,/* A B R(A) := newmodule(R(A),Syms(B)) */
135
+ OP_EXEC,/* A Bx R(A) := blockexec(R(A),SEQ[Bx]) */
136
+ OP_METHOD,/* A B R(A).newmethod(Syms(B),R(A+1)) */
137
+ OP_SCLASS,/* A B R(A) := R(B).singleton_class */
138
+ OP_TCLASS,/* A R(A) := target_class */
139
+
140
+ OP_DEBUG,/* A B C print R(A),R(B),R(C) */
141
+ OP_STOP,/* stop VM */
142
+ OP_ERR,/* Bx raise RuntimeError with message Lit(Bx) */
143
+
144
+ OP_RSVD1,/* reserved instruction #1 */
145
+ OP_RSVD2,/* reserved instruction #2 */
146
+ OP_RSVD3,/* reserved instruction #3 */
147
+ OP_RSVD4,/* reserved instruction #4 */
148
+ OP_RSVD5,/* reserved instruction #5 */
149
+ };
150
+
151
+ #define OP_L_STRICT 1
152
+ #define OP_L_CAPTURE 2
153
+ #define OP_L_METHOD OP_L_STRICT
154
+ #define OP_L_LAMBDA (OP_L_STRICT|OP_L_CAPTURE)
155
+ #define OP_L_BLOCK OP_L_CAPTURE
156
+
157
+ #define OP_R_NORMAL 0
158
+ #define OP_R_BREAK 1
159
+ #define OP_R_RETURN 2
160
+
161
+ #endif /* MRUBY_OPCODE_H */
@@ -0,0 +1,131 @@
1
+ /*
2
+ ** mruby/proc.h - Proc class
3
+ **
4
+ ** See Copyright Notice in mruby.h
5
+ */
6
+
7
+ #ifndef MRUBY_PROC_H
8
+ #define MRUBY_PROC_H
9
+
10
+ #include "common.h"
11
+ #include <mruby/irep.h>
12
+
13
+ /**
14
+ * Proc class
15
+ */
16
+ MRB_BEGIN_DECL
17
+
18
+ struct REnv {
19
+ MRB_OBJECT_HEADER;
20
+ mrb_value *stack;
21
+ struct mrb_context *cxt;
22
+ mrb_sym mid;
23
+ };
24
+
25
+ /* flags (21bits): 1(shared flag):10(cioff/bidx):10(stack_len) */
26
+ #define MRB_ENV_SET_STACK_LEN(e,len) (e)->flags = (((e)->flags & ~0x3ff)|((unsigned int)(len) & 0x3ff))
27
+ #define MRB_ENV_STACK_LEN(e) ((mrb_int)((e)->flags & 0x3ff))
28
+ #define MRB_ENV_STACK_UNSHARED (1<<20)
29
+ #define MRB_ENV_UNSHARE_STACK(e) (e)->flags |= MRB_ENV_STACK_UNSHARED
30
+ #define MRB_ENV_STACK_SHARED_P(e) (((e)->flags & MRB_ENV_STACK_UNSHARED) == 0)
31
+ #define MRB_ENV_BIDX(e) (((e)->flags >> 10) & 0x3ff)
32
+ #define MRB_ENV_SET_BIDX(e,idx) (e)->flags = (((e)->flags & ~(0x3ff<<10))|((unsigned int)(idx) & 0x3ff)<<10)
33
+
34
+ void mrb_env_unshare(mrb_state*, struct REnv*);
35
+
36
+ struct RProc {
37
+ MRB_OBJECT_HEADER;
38
+ union {
39
+ mrb_irep *irep;
40
+ mrb_func_t func;
41
+ } body;
42
+ struct RProc *upper;
43
+ union {
44
+ struct RClass *target_class;
45
+ struct REnv *env;
46
+ } e;
47
+ };
48
+
49
+ /* aspec access */
50
+ #define MRB_ASPEC_REQ(a) (((a) >> 18) & 0x1f)
51
+ #define MRB_ASPEC_OPT(a) (((a) >> 13) & 0x1f)
52
+ #define MRB_ASPEC_REST(a) (((a) >> 12) & 0x1)
53
+ #define MRB_ASPEC_POST(a) (((a) >> 7) & 0x1f)
54
+ #define MRB_ASPEC_KEY(a) (((a) >> 2) & 0x1f)
55
+ #define MRB_ASPEC_KDICT(a) ((a) & (1<<1))
56
+ #define MRB_ASPEC_BLOCK(a) ((a) & 1)
57
+
58
+ #define MRB_PROC_CFUNC_FL 128
59
+ #define MRB_PROC_CFUNC_P(p) (((p)->flags & MRB_PROC_CFUNC_FL) != 0)
60
+ #define MRB_PROC_CFUNC(p) (p)->body.func
61
+ #define MRB_PROC_STRICT 256
62
+ #define MRB_PROC_STRICT_P(p) (((p)->flags & MRB_PROC_STRICT) != 0)
63
+ #define MRB_PROC_ORPHAN 512
64
+ #define MRB_PROC_ORPHAN_P(p) (((p)->flags & MRB_PROC_ORPHAN) != 0)
65
+ #define MRB_PROC_ENVSET 1024
66
+ #define MRB_PROC_ENV_P(p) (((p)->flags & MRB_PROC_ENVSET) != 0)
67
+ #define MRB_PROC_ENV(p) (MRB_PROC_ENV_P(p) ? (p)->e.env : NULL)
68
+ #define MRB_PROC_TARGET_CLASS(p) (MRB_PROC_ENV_P(p) ? (p)->e.env->c : (p)->e.target_class)
69
+ #define MRB_PROC_SET_TARGET_CLASS(p,tc) do {\
70
+ if (MRB_PROC_ENV_P(p)) {\
71
+ (p)->e.env->c = (tc);\
72
+ mrb_field_write_barrier(mrb, (struct RBasic*)(p)->e.env, (struct RBasic*)tc);\
73
+ }\
74
+ else {\
75
+ (p)->e.target_class = (tc);\
76
+ mrb_field_write_barrier(mrb, (struct RBasic*)p, (struct RBasic*)tc);\
77
+ }\
78
+ } while (0)
79
+ #define MRB_PROC_SCOPE 2048
80
+ #define MRB_PROC_SCOPE_P(p) (((p)->flags & MRB_PROC_SCOPE) != 0)
81
+
82
+ #define mrb_proc_ptr(v) ((struct RProc*)(mrb_ptr(v)))
83
+
84
+ struct RProc *mrb_proc_new(mrb_state*, mrb_irep*);
85
+ struct RProc *mrb_closure_new(mrb_state*, mrb_irep*);
86
+ MRB_API struct RProc *mrb_proc_new_cfunc(mrb_state*, mrb_func_t);
87
+ MRB_API struct RProc *mrb_closure_new_cfunc(mrb_state *mrb, mrb_func_t func, int nlocals);
88
+ void mrb_proc_copy(struct RProc *a, struct RProc *b);
89
+
90
+ /* implementation of #send method */
91
+ MRB_API mrb_value mrb_f_send(mrb_state *mrb, mrb_value self);
92
+
93
+ /* following functions are defined in mruby-proc-ext so please include it when using */
94
+ MRB_API struct RProc *mrb_proc_new_cfunc_with_env(mrb_state*, mrb_func_t, mrb_int, const mrb_value*);
95
+ MRB_API mrb_value mrb_proc_cfunc_env_get(mrb_state*, mrb_int);
96
+ /* old name */
97
+ #define mrb_cfunc_env_get(mrb, idx) mrb_proc_cfunc_env_get(mrb, idx)
98
+
99
+ #ifdef MRB_METHOD_TABLE_INLINE
100
+
101
+ #define MRB_METHOD_FUNC_FL ((uintptr_t)1U<<(sizeof(uintptr_t)*8-1))
102
+ #define MRB_METHOD_FUNC_P(m) ((uintptr_t)(m)&MRB_METHOD_FUNC_FL)
103
+ #define MRB_METHOD_FUNC(m) ((mrb_func_t)((uintptr_t)(m)&(~MRB_METHOD_FUNC_FL)))
104
+ #define MRB_METHOD_FROM_FUNC(m,fn) m=(mrb_method_t)((struct RProc*)((uintptr_t)(fn)|MRB_METHOD_FUNC_FL))
105
+ #define MRB_METHOD_FROM_PROC(m,pr) m=(mrb_method_t)(struct RProc*)(pr)
106
+ #define MRB_METHOD_PROC_P(m) (!MRB_METHOD_FUNC_P(m))
107
+ #define MRB_METHOD_PROC(m) ((struct RProc*)(m))
108
+ #define MRB_METHOD_UNDEF_P(m) ((m)==0)
109
+
110
+ #else
111
+
112
+ #define MRB_METHOD_FUNC_P(m) ((m).func_p)
113
+ #define MRB_METHOD_FUNC(m) ((m).func)
114
+ #define MRB_METHOD_FROM_FUNC(m,fn) do{(m).func_p=TRUE;(m).func=(fn);}while(0)
115
+ #define MRB_METHOD_FROM_PROC(m,pr) do{(m).func_p=FALSE;(m).proc=(pr);}while(0)
116
+ #define MRB_METHOD_PROC_P(m) (!MRB_METHOD_FUNC_P(m))
117
+ #define MRB_METHOD_PROC(fn) ((m).proc)
118
+ #define MRB_METHOD_UNDEF_P(m) ((m).proc==NULL)
119
+
120
+ #endif /* MRB_METHOD_TABLE_INLINE */
121
+
122
+ #define MRB_METHOD_CFUNC_P(m) (MRB_METHOD_FUNC_P(m)?TRUE:(MRB_METHOD_PROC(m)?(MRB_PROC_CFUNC_P(MRB_METHOD_PROC(m))):FALSE))
123
+ #define MRB_METHOD_CFUNC(m) (MRB_METHOD_FUNC_P(m)?MRB_METHOD_FUNC(m):((MRB_METHOD_PROC(m)&&MRB_PROC_CFUNC_P(MRB_METHOD_PROC(m)))?MRB_PROC_CFUNC(MRB_METHOD_PROC(m)):NULL))
124
+
125
+
126
+ #include <mruby/khash.h>
127
+ KHASH_DECLARE(mt, mrb_sym, mrb_method_t, TRUE)
128
+
129
+ MRB_END_DECL
130
+
131
+ #endif /* MRUBY_PROC_H */
@@ -0,0 +1,49 @@
1
+ /*
2
+ ** mruby/range.h - Range class
3
+ **
4
+ ** See Copyright Notice in mruby.h
5
+ */
6
+
7
+ #ifndef MRUBY_RANGE_H
8
+ #define MRUBY_RANGE_H
9
+
10
+ #include "common.h"
11
+
12
+ /**
13
+ * Range class
14
+ */
15
+ MRB_BEGIN_DECL
16
+
17
+ typedef struct mrb_range_edges {
18
+ mrb_value beg;
19
+ mrb_value end;
20
+ } mrb_range_edges;
21
+
22
+ struct RRange {
23
+ MRB_OBJECT_HEADER;
24
+ mrb_range_edges *edges;
25
+ mrb_bool excl : 1;
26
+ };
27
+
28
+ MRB_API struct RRange* mrb_range_ptr(mrb_state *mrb, mrb_value v);
29
+ #define mrb_range_raw_ptr(v) ((struct RRange*)mrb_ptr(v))
30
+ #define mrb_range_value(p) mrb_obj_value((void*)(p))
31
+
32
+ /*
33
+ * Initializes a Range.
34
+ *
35
+ * If the third parameter is FALSE then it includes the last value in the range.
36
+ * If the third parameter is TRUE then it excludes the last value in the range.
37
+ *
38
+ * @param start the beginning value.
39
+ * @param end the ending value.
40
+ * @param exclude represents the inclusion or exclusion of the last value.
41
+ */
42
+ MRB_API mrb_value mrb_range_new(mrb_state *mrb, mrb_value start, mrb_value end, mrb_bool exclude);
43
+
44
+ MRB_API mrb_int mrb_range_beg_len(mrb_state *mrb, mrb_value range, mrb_int *begp, mrb_int *lenp, mrb_int len, mrb_bool trunc);
45
+ mrb_value mrb_get_values_at(mrb_state *mrb, mrb_value obj, mrb_int olen, mrb_int argc, const mrb_value *argv, mrb_value (*func)(mrb_state*, mrb_value, mrb_int));
46
+
47
+ MRB_END_DECL
48
+
49
+ #endif /* MRUBY_RANGE_H */
@@ -0,0 +1,16 @@
1
+ /*
2
+ ** mruby/re.h - Regexp class
3
+ **
4
+ ** See Copyright Notice in mruby.h
5
+ */
6
+
7
+ #ifndef MRUBY_RE_H
8
+ #define MRUBY_RE_H
9
+
10
+ MRB_BEGIN_DECL
11
+
12
+ #define REGEXP_CLASS "Regexp"
13
+
14
+ MRB_END_DECL
15
+
16
+ #endif /* RE_H */
@@ -0,0 +1,440 @@
1
+ /*
2
+ ** mruby/string.h - String class
3
+ **
4
+ ** See Copyright Notice in mruby.h
5
+ */
6
+
7
+ #ifndef MRUBY_STRING_H
8
+ #define MRUBY_STRING_H
9
+
10
+ #include "common.h"
11
+
12
+ /**
13
+ * String class
14
+ */
15
+ MRB_BEGIN_DECL
16
+
17
+ extern const char mrb_digitmap[];
18
+
19
+ #define RSTRING_EMBED_LEN_MAX ((mrb_int)(sizeof(void*) * 3 - 1))
20
+
21
+ struct RString {
22
+ MRB_OBJECT_HEADER;
23
+ union {
24
+ struct {
25
+ mrb_int len;
26
+ union {
27
+ mrb_int capa;
28
+ struct mrb_shared_string *shared;
29
+ struct RString *fshared;
30
+ } aux;
31
+ char *ptr;
32
+ } heap;
33
+ char ary[RSTRING_EMBED_LEN_MAX + 1];
34
+ } as;
35
+ };
36
+
37
+ #define RSTR_EMBED_P(s) ((s)->flags & MRB_STR_EMBED)
38
+ #define RSTR_SET_EMBED_FLAG(s) ((s)->flags |= MRB_STR_EMBED)
39
+ #define RSTR_UNSET_EMBED_FLAG(s) ((s)->flags &= ~(MRB_STR_EMBED|MRB_STR_EMBED_LEN_MASK))
40
+ #define RSTR_SET_EMBED_LEN(s, n) do {\
41
+ size_t tmp_n = (n);\
42
+ s->flags &= ~MRB_STR_EMBED_LEN_MASK;\
43
+ s->flags |= (tmp_n) << MRB_STR_EMBED_LEN_SHIFT;\
44
+ } while (0)
45
+ #define RSTR_SET_LEN(s, n) do {\
46
+ if (RSTR_EMBED_P(s)) {\
47
+ RSTR_SET_EMBED_LEN((s),(n));\
48
+ }\
49
+ else {\
50
+ s->as.heap.len = (mrb_int)(n);\
51
+ }\
52
+ } while (0)
53
+ #define RSTR_EMBED_LEN(s)\
54
+ (mrb_int)(((s)->flags & MRB_STR_EMBED_LEN_MASK) >> MRB_STR_EMBED_LEN_SHIFT)
55
+ #define RSTR_PTR(s) ((RSTR_EMBED_P(s)) ? (s)->as.ary : (s)->as.heap.ptr)
56
+ #define RSTR_LEN(s) ((RSTR_EMBED_P(s)) ? RSTR_EMBED_LEN(s) : (s)->as.heap.len)
57
+ #define RSTR_CAPA(s) (RSTR_EMBED_P(s) ? RSTRING_EMBED_LEN_MAX : (s)->as.heap.aux.capa)
58
+
59
+ #define RSTR_SHARED_P(s) ((s)->flags & MRB_STR_SHARED)
60
+ #define RSTR_SET_SHARED_FLAG(s) ((s)->flags |= MRB_STR_SHARED)
61
+ #define RSTR_UNSET_SHARED_FLAG(s) ((s)->flags &= ~MRB_STR_SHARED)
62
+
63
+ #define RSTR_FSHARED_P(s) ((s)->flags & MRB_STR_FSHARED)
64
+ #define RSTR_SET_FSHARED_FLAG(s) ((s)->flags |= MRB_STR_FSHARED)
65
+ #define RSTR_UNSET_FSHARED_FLAG(s) ((s)->flags &= ~MRB_STR_FSHARED)
66
+
67
+ #define RSTR_NOFREE_P(s) ((s)->flags & MRB_STR_NOFREE)
68
+ #define RSTR_SET_NOFREE_FLAG(s) ((s)->flags |= MRB_STR_NOFREE)
69
+ #define RSTR_UNSET_NOFREE_FLAG(s) ((s)->flags &= ~MRB_STR_NOFREE)
70
+
71
+ #define RSTR_POOL_P(s) ((s)->flags & MRB_STR_POOL)
72
+ #define RSTR_SET_POOL_FLAG(s) ((s)->flags |= MRB_STR_POOL)
73
+
74
+ /*
75
+ * Returns a pointer from a Ruby string
76
+ */
77
+ #define mrb_str_ptr(s) ((struct RString*)(mrb_ptr(s)))
78
+ #define RSTRING(s) mrb_str_ptr(s)
79
+ #define RSTRING_PTR(s) RSTR_PTR(RSTRING(s))
80
+ #define RSTRING_EMBED_LEN(s) RSTR_EMBED_LEN(RSTRING(s))
81
+ #define RSTRING_LEN(s) RSTR_LEN(RSTRING(s))
82
+ #define RSTRING_CAPA(s) RSTR_CAPA(RSTRING(s))
83
+ #define RSTRING_END(s) (RSTRING_PTR(s) + RSTRING_LEN(s))
84
+ MRB_API mrb_int mrb_str_strlen(mrb_state*, struct RString*);
85
+
86
+ #define MRB_STR_SHARED 1
87
+ #define MRB_STR_FSHARED 2
88
+ #define MRB_STR_NOFREE 4
89
+ #define MRB_STR_POOL 8
90
+ #define MRB_STR_NO_UTF 16
91
+ #define MRB_STR_EMBED 32
92
+ #define MRB_STR_EMBED_LEN_MASK 0x7c0
93
+ #define MRB_STR_EMBED_LEN_SHIFT 6
94
+
95
+ void mrb_gc_free_str(mrb_state*, struct RString*);
96
+ MRB_API void mrb_str_modify(mrb_state*, struct RString*);
97
+
98
+ /*
99
+ * Finds the index of a substring in a string
100
+ */
101
+ MRB_API mrb_int mrb_str_index(mrb_state*, mrb_value, const char*, mrb_int, mrb_int);
102
+ #define mrb_str_index_lit(mrb, str, lit, off) mrb_str_index(mrb, str, lit, mrb_strlen_lit(lit), off);
103
+
104
+ /*
105
+ * Appends self to other. Returns self as a concatnated string.
106
+ *
107
+ *
108
+ * Example:
109
+ *
110
+ * !!!c
111
+ * int
112
+ * main(int argc,
113
+ * char **argv)
114
+ * {
115
+ * // Variable declarations.
116
+ * mrb_value str1;
117
+ * mrb_value str2;
118
+ *
119
+ * mrb_state *mrb = mrb_open();
120
+ * if (!mrb)
121
+ * {
122
+ * // handle error
123
+ * }
124
+ *
125
+ * // Creates new Ruby strings.
126
+ * str1 = mrb_str_new_lit(mrb, "abc");
127
+ * str2 = mrb_str_new_lit(mrb, "def");
128
+ *
129
+ * // Concatnates str2 to str1.
130
+ * mrb_str_concat(mrb, str1, str2);
131
+ *
132
+ * // Prints new Concatnated Ruby string.
133
+ * mrb_p(mrb, str1);
134
+ *
135
+ * mrb_close(mrb);
136
+ * return 0;
137
+ * }
138
+ *
139
+ *
140
+ * Result:
141
+ *
142
+ * => "abcdef"
143
+ *
144
+ * @param [mrb_state] mrb The current mruby state.
145
+ * @param [mrb_value] self String to concatenate.
146
+ * @param [mrb_value] other String to append to self.
147
+ * @return [mrb_value] Returns a new String appending other to self.
148
+ */
149
+ MRB_API void mrb_str_concat(mrb_state*, mrb_value, mrb_value);
150
+
151
+ /*
152
+ * Adds two strings together.
153
+ *
154
+ *
155
+ * Example:
156
+ *
157
+ * !!!c
158
+ * int
159
+ * main(int argc,
160
+ * char **argv)
161
+ * {
162
+ * // Variable declarations.
163
+ * mrb_value a;
164
+ * mrb_value b;
165
+ * mrb_value c;
166
+ *
167
+ * mrb_state *mrb = mrb_open();
168
+ * if (!mrb)
169
+ * {
170
+ * // handle error
171
+ * }
172
+ *
173
+ * // Creates two Ruby strings from the passed in C strings.
174
+ * a = mrb_str_new_lit(mrb, "abc");
175
+ * b = mrb_str_new_lit(mrb, "def");
176
+ *
177
+ * // Prints both C strings.
178
+ * mrb_p(mrb, a);
179
+ * mrb_p(mrb, b);
180
+ *
181
+ * // Concatnates both Ruby strings.
182
+ * c = mrb_str_plus(mrb, a, b);
183
+ *
184
+ * // Prints new Concatnated Ruby string.
185
+ * mrb_p(mrb, c);
186
+ *
187
+ * mrb_close(mrb);
188
+ * return 0;
189
+ * }
190
+ *
191
+ *
192
+ * Result:
193
+ *
194
+ * => "abc" # First string
195
+ * => "def" # Second string
196
+ * => "abcdef" # First & Second concatnated.
197
+ *
198
+ * @param [mrb_state] mrb The current mruby state.
199
+ * @param [mrb_value] a First string to concatenate.
200
+ * @param [mrb_value] b Second string to concatenate.
201
+ * @return [mrb_value] Returns a new String containing a concatenated to b.
202
+ */
203
+ MRB_API mrb_value mrb_str_plus(mrb_state*, mrb_value, mrb_value);
204
+
205
+ /*
206
+ * Converts pointer into a Ruby string.
207
+ *
208
+ * @param [mrb_state] mrb The current mruby state.
209
+ * @param [void*] p The pointer to convert to Ruby string.
210
+ * @return [mrb_value] Returns a new Ruby String.
211
+ */
212
+ MRB_API mrb_value mrb_ptr_to_str(mrb_state *, void*);
213
+
214
+ /*
215
+ * Returns an object as a Ruby string.
216
+ *
217
+ * @param [mrb_state] mrb The current mruby state.
218
+ * @param [mrb_value] obj An object to return as a Ruby string.
219
+ * @return [mrb_value] An object as a Ruby string.
220
+ */
221
+ MRB_API mrb_value mrb_obj_as_string(mrb_state *mrb, mrb_value obj);
222
+
223
+ /*
224
+ * Resizes the string's length. Returns the amount of characters
225
+ * in the specified by len.
226
+ *
227
+ * Example:
228
+ *
229
+ * !!!c
230
+ * int
231
+ * main(int argc,
232
+ * char **argv)
233
+ * {
234
+ * // Variable declaration.
235
+ * mrb_value str;
236
+ *
237
+ * mrb_state *mrb = mrb_open();
238
+ * if (!mrb)
239
+ * {
240
+ * // handle error
241
+ * }
242
+ * // Creates a new string.
243
+ * str = mrb_str_new_lit(mrb, "Hello, world!");
244
+ * // Returns 5 characters of
245
+ * mrb_str_resize(mrb, str, 5);
246
+ * mrb_p(mrb, str);
247
+ *
248
+ * mrb_close(mrb);
249
+ * return 0;
250
+ * }
251
+ *
252
+ * Result:
253
+ *
254
+ * => "Hello"
255
+ *
256
+ * @param [mrb_state] mrb The current mruby state.
257
+ * @param [mrb_value] str The Ruby string to resize.
258
+ * @param [mrb_value] len The length.
259
+ * @return [mrb_value] An object as a Ruby string.
260
+ */
261
+ MRB_API mrb_value mrb_str_resize(mrb_state *mrb, mrb_value str, mrb_int len);
262
+
263
+ /*
264
+ * Returns a sub string.
265
+ *
266
+ * Example:
267
+ *
268
+ * !!!c
269
+ * int
270
+ * main(int argc,
271
+ * char const **argv)
272
+ * {
273
+ * // Variable declarations.
274
+ * mrb_value str1;
275
+ * mrb_value str2;
276
+ *
277
+ * mrb_state *mrb = mrb_open();
278
+ * if (!mrb)
279
+ * {
280
+ * // handle error
281
+ * }
282
+ * // Creates new string.
283
+ * str1 = mrb_str_new_lit(mrb, "Hello, world!");
284
+ * // Returns a sub-string within the range of 0..2
285
+ * str2 = mrb_str_substr(mrb, str1, 0, 2);
286
+ *
287
+ * // Prints sub-string.
288
+ * mrb_p(mrb, str2);
289
+ *
290
+ * mrb_close(mrb);
291
+ * return 0;
292
+ * }
293
+ *
294
+ * Result:
295
+ *
296
+ * => "He"
297
+ *
298
+ * @param [mrb_state] mrb The current mruby state.
299
+ * @param [mrb_value] str Ruby string.
300
+ * @param [mrb_int] beg The beginning point of the sub-string.
301
+ * @param [mrb_int] len The end point of the sub-string.
302
+ * @return [mrb_value] An object as a Ruby sub-string.
303
+ */
304
+ MRB_API mrb_value mrb_str_substr(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len);
305
+
306
+ /*
307
+ * Returns a Ruby string type.
308
+ *
309
+ *
310
+ * @param [mrb_state] mrb The current mruby state.
311
+ * @param [mrb_value] str Ruby string.
312
+ * @return [mrb_value] A Ruby string.
313
+ */
314
+ MRB_API mrb_value mrb_string_type(mrb_state *mrb, mrb_value str);
315
+
316
+ MRB_API mrb_value mrb_check_string_type(mrb_state *mrb, mrb_value str);
317
+ MRB_API mrb_value mrb_str_new_capa(mrb_state *mrb, size_t capa);
318
+ MRB_API mrb_value mrb_str_buf_new(mrb_state *mrb, size_t capa);
319
+
320
+ MRB_API const char *mrb_string_value_cstr(mrb_state *mrb, mrb_value *ptr);
321
+ MRB_API const char *mrb_string_value_ptr(mrb_state *mrb, mrb_value str);
322
+ /*
323
+ * Returns the length of the Ruby string.
324
+ *
325
+ *
326
+ * @param [mrb_state] mrb The current mruby state.
327
+ * @param [mrb_value] str Ruby string.
328
+ * @return [mrb_int] The length of the passed in Ruby string.
329
+ */
330
+ MRB_API mrb_int mrb_string_value_len(mrb_state *mrb, mrb_value str);
331
+
332
+ /*
333
+ * Duplicates a string object.
334
+ *
335
+ *
336
+ * @param [mrb_state] mrb The current mruby state.
337
+ * @param [mrb_value] str Ruby string.
338
+ * @return [mrb_value] Duplicated Ruby string.
339
+ */
340
+ MRB_API mrb_value mrb_str_dup(mrb_state *mrb, mrb_value str);
341
+
342
+ /*
343
+ * Returns a symbol from a passed in Ruby string.
344
+ *
345
+ * @param [mrb_state] mrb The current mruby state.
346
+ * @param [mrb_value] self Ruby string.
347
+ * @return [mrb_value] A symbol.
348
+ */
349
+ MRB_API mrb_value mrb_str_intern(mrb_state *mrb, mrb_value self);
350
+
351
+ MRB_API mrb_value mrb_str_to_inum(mrb_state *mrb, mrb_value str, mrb_int base, mrb_bool badcheck);
352
+ MRB_API double mrb_str_to_dbl(mrb_state *mrb, mrb_value str, mrb_bool badcheck);
353
+
354
+ /*
355
+ * Returns a converted string type.
356
+ */
357
+ MRB_API mrb_value mrb_str_to_str(mrb_state *mrb, mrb_value str);
358
+
359
+ /*
360
+ * Returns true if the strings match and false if the strings don't match.
361
+ *
362
+ * @param [mrb_state] mrb The current mruby state.
363
+ * @param [mrb_value] str1 Ruby string to compare.
364
+ * @param [mrb_value] str2 Ruby string to compare.
365
+ * @return [mrb_value] boolean value.
366
+ */
367
+ MRB_API mrb_bool mrb_str_equal(mrb_state *mrb, mrb_value str1, mrb_value str2);
368
+
369
+ /*
370
+ * Returns a concated string comprised of a Ruby string and a C string.
371
+ *
372
+ * @param [mrb_state] mrb The current mruby state.
373
+ * @param [mrb_value] str Ruby string.
374
+ * @param [const char *] ptr A C string.
375
+ * @param [size_t] len length of C string.
376
+ * @return [mrb_value] A Ruby string.
377
+ * @see mrb_str_cat_cstr
378
+ */
379
+ MRB_API mrb_value mrb_str_cat(mrb_state *mrb, mrb_value str, const char *ptr, size_t len);
380
+
381
+ /*
382
+ * Returns a concated string comprised of a Ruby string and a C string.
383
+ *
384
+ * @param [mrb_state] mrb The current mruby state.
385
+ * @param [mrb_value] str Ruby string.
386
+ * @param [const char *] ptr A C string.
387
+ * @return [mrb_value] A Ruby string.
388
+ * @see mrb_str_cat
389
+ */
390
+ MRB_API mrb_value mrb_str_cat_cstr(mrb_state *mrb, mrb_value str, const char *ptr);
391
+ MRB_API mrb_value mrb_str_cat_str(mrb_state *mrb, mrb_value str, mrb_value str2);
392
+ #define mrb_str_cat_lit(mrb, str, lit) mrb_str_cat(mrb, str, lit, mrb_strlen_lit(lit))
393
+
394
+ /*
395
+ * Adds str2 to the end of str1.
396
+ */
397
+ MRB_API mrb_value mrb_str_append(mrb_state *mrb, mrb_value str, mrb_value str2);
398
+
399
+ /*
400
+ * Returns 0 if both Ruby strings are equal. Returns a value < 0 if Ruby str1 is less than Ruby str2. Returns a value > 0 if Ruby str2 is greater than Ruby str1.
401
+ */
402
+ MRB_API int mrb_str_cmp(mrb_state *mrb, mrb_value str1, mrb_value str2);
403
+
404
+ /*
405
+ * Returns a newly allocated C string from a Ruby string.
406
+ * This is an utility function to pass a Ruby string to C library functions.
407
+ *
408
+ * - Returned string does not contain any NUL characters (but terminator).
409
+ * - It raises an ArgumentError exception if Ruby string contains
410
+ * NUL characters.
411
+ * - Retured string will be freed automatically on next GC.
412
+ * - Caller can modify returned string without affecting Ruby string
413
+ * (e.g. it can be used for mkstemp(3)).
414
+ *
415
+ * @param [mrb_state *] mrb The current mruby state.
416
+ * @param [mrb_value] str Ruby string. Must be an instance of String.
417
+ * @return [char *] A newly allocated C string.
418
+ */
419
+ MRB_API char *mrb_str_to_cstr(mrb_state *mrb, mrb_value str);
420
+
421
+ mrb_value mrb_str_pool(mrb_state *mrb, mrb_value str);
422
+ uint32_t mrb_str_hash(mrb_state *mrb, mrb_value str);
423
+ mrb_value mrb_str_dump(mrb_state *mrb, mrb_value str);
424
+
425
+ /*
426
+ * Returns a printable version of str, surrounded by quote marks, with special characters escaped.
427
+ */
428
+ mrb_value mrb_str_inspect(mrb_state *mrb, mrb_value str);
429
+
430
+ void mrb_noregexp(mrb_state *mrb, mrb_value self);
431
+ void mrb_regexp_check(mrb_state *mrb, mrb_value obj);
432
+
433
+ /* For backward compatibility */
434
+ #define mrb_str_cat2(mrb, str, ptr) mrb_str_cat_cstr(mrb, str, ptr)
435
+ #define mrb_str_buf_cat(mrb, str, ptr, len) mrb_str_cat(mrb, str, ptr, len)
436
+ #define mrb_str_buf_append(mrb, str, str2) mrb_str_cat_str(mrb, str, str2)
437
+
438
+ MRB_END_DECL
439
+
440
+ #endif /* MRUBY_STRING_H */