ruby2d 0.11.2 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (231) hide show
  1. checksums.yaml +4 -4
  2. data/assets/include/GLES2/gl2.h +656 -0
  3. data/assets/include/GLES2/gl2ext.h +3949 -0
  4. data/assets/include/GLES2/gl2ext_angle.h +701 -0
  5. data/assets/include/GLES2/gl2platform.h +27 -0
  6. data/assets/include/GLES3/gl3.h +1192 -0
  7. data/assets/include/GLES3/gl31.h +1507 -0
  8. data/assets/include/GLES3/gl32.h +1808 -0
  9. data/assets/include/GLES3/gl3platform.h +27 -0
  10. data/assets/include/KHR/khrplatform.h +290 -0
  11. data/assets/include/SDL2/SDL.h +1 -0
  12. data/assets/include/SDL2/SDL_assert.h +4 -2
  13. data/assets/include/SDL2/SDL_atomic.h +20 -0
  14. data/assets/include/SDL2/SDL_audio.h +40 -4
  15. data/assets/include/SDL2/SDL_blendmode.h +4 -6
  16. data/assets/include/SDL2/SDL_clipboard.h +47 -0
  17. data/assets/include/SDL2/SDL_config.h +6 -2
  18. data/assets/include/SDL2/SDL_config_android.h +2 -0
  19. data/assets/include/SDL2/SDL_config_emscripten.h +2 -0
  20. data/assets/include/SDL2/SDL_config_iphoneos.h +3 -1
  21. data/assets/include/SDL2/SDL_config_macosx.h +3 -6
  22. data/assets/include/SDL2/SDL_config_minimal.h +18 -11
  23. data/assets/include/SDL2/SDL_config_ngage.h +89 -0
  24. data/assets/include/SDL2/SDL_config_os2.h +5 -3
  25. data/assets/include/SDL2/SDL_config_pandora.h +1 -0
  26. data/assets/include/SDL2/SDL_config_windows.h +71 -45
  27. data/assets/include/SDL2/SDL_config_wingdk.h +253 -0
  28. data/assets/include/SDL2/SDL_config_winrt.h +11 -49
  29. data/assets/include/SDL2/SDL_config_xbox.h +235 -0
  30. data/assets/include/SDL2/SDL_cpuinfo.h +39 -4
  31. data/assets/include/SDL2/SDL_egl.h +59 -9
  32. data/assets/include/SDL2/SDL_endian.h +34 -3
  33. data/assets/include/SDL2/SDL_events.h +32 -1
  34. data/assets/include/SDL2/SDL_filesystem.h +5 -1
  35. data/assets/include/SDL2/SDL_gamecontroller.h +78 -5
  36. data/assets/include/SDL2/SDL_guid.h +100 -0
  37. data/assets/include/SDL2/SDL_hints.h +645 -43
  38. data/assets/include/SDL2/SDL_image.h +2045 -33
  39. data/assets/include/SDL2/SDL_joystick.h +127 -7
  40. data/assets/include/SDL2/SDL_keyboard.h +38 -1
  41. data/assets/include/SDL2/SDL_keycode.h +6 -1
  42. data/assets/include/SDL2/SDL_log.h +2 -2
  43. data/assets/include/SDL2/SDL_main.h +42 -2
  44. data/assets/include/SDL2/SDL_metal.h +2 -1
  45. data/assets/include/SDL2/SDL_mixer.h +2529 -396
  46. data/assets/include/SDL2/SDL_mouse.h +12 -1
  47. data/assets/include/SDL2/SDL_opengl.h +0 -51
  48. data/assets/include/SDL2/SDL_opengl_glext.h +2260 -231
  49. data/assets/include/SDL2/SDL_opengles2_gl2.h +374 -339
  50. data/assets/include/SDL2/SDL_opengles2_gl2ext.h +3479 -1496
  51. data/assets/include/SDL2/SDL_opengles2_gl2platform.h +6 -9
  52. data/assets/include/SDL2/SDL_opengles2_khrplatform.h +43 -14
  53. data/assets/include/SDL2/SDL_platform.h +32 -6
  54. data/assets/include/SDL2/SDL_rect.h +154 -2
  55. data/assets/include/SDL2/SDL_render.h +46 -17
  56. data/assets/include/SDL2/SDL_revision.h +4 -0
  57. data/assets/include/SDL2/SDL_rwops.h +1 -15
  58. data/assets/include/SDL2/SDL_scancode.h +46 -21
  59. data/assets/include/SDL2/SDL_sensor.h +24 -3
  60. data/assets/include/SDL2/SDL_stdinc.h +119 -8
  61. data/assets/include/SDL2/SDL_surface.h +3 -1
  62. data/assets/include/SDL2/SDL_system.h +66 -6
  63. data/assets/include/SDL2/SDL_syswm.h +2 -0
  64. data/assets/include/SDL2/SDL_test_common.h +1 -0
  65. data/assets/include/SDL2/SDL_test_font.h +90 -3
  66. data/assets/include/SDL2/SDL_thread.h +3 -3
  67. data/assets/include/SDL2/SDL_touch.h +8 -0
  68. data/assets/include/SDL2/SDL_ttf.h +2084 -155
  69. data/assets/include/SDL2/SDL_version.h +19 -3
  70. data/assets/include/SDL2/SDL_video.h +71 -9
  71. data/assets/include/SDL2/begin_code.h +4 -4
  72. data/assets/include/mrbconf.h +15 -17
  73. data/assets/include/mruby/array.h +8 -21
  74. data/assets/include/mruby/boxing_nan.h +115 -86
  75. data/assets/include/mruby/boxing_word.h +104 -78
  76. data/assets/include/mruby/common.h +6 -0
  77. data/assets/include/mruby/compile.h +3 -4
  78. data/assets/include/mruby/debug.h +4 -2
  79. data/assets/include/mruby/dump.h +5 -2
  80. data/assets/include/mruby/error.h +12 -2
  81. data/assets/include/mruby/gc.h +2 -0
  82. data/assets/include/mruby/hash.h +1 -3
  83. data/assets/include/mruby/irep.h +4 -4
  84. data/assets/include/mruby/numeric.h +21 -13
  85. data/assets/include/mruby/opcode.h +30 -0
  86. data/assets/include/mruby/ops.h +99 -101
  87. data/assets/include/mruby/presym/scanning.h +15 -9
  88. data/assets/include/mruby/proc.h +4 -2
  89. data/assets/include/mruby/string.h +3 -24
  90. data/assets/include/mruby/value.h +80 -40
  91. data/assets/include/mruby/variable.h +0 -15
  92. data/assets/include/mruby/version.h +5 -5
  93. data/assets/include/mruby.h +86 -16
  94. data/assets/macos/universal/bin/mrbc +0 -0
  95. data/assets/macos/universal/lib/libFLAC.a +0 -0
  96. data/assets/macos/universal/lib/libSDL2.a +0 -0
  97. data/assets/macos/universal/lib/libSDL2_image.a +0 -0
  98. data/assets/macos/universal/lib/libSDL2_mixer.a +0 -0
  99. data/assets/macos/universal/lib/libSDL2_ttf.a +0 -0
  100. data/assets/macos/universal/lib/libavif.a +0 -0
  101. data/assets/macos/universal/lib/libbrotlicommon-static.a +0 -0
  102. data/assets/macos/universal/lib/libbrotlidec-static.a +0 -0
  103. data/assets/macos/universal/lib/libfreetype.a +0 -0
  104. data/assets/macos/universal/lib/libgraphite2.a +0 -0
  105. data/assets/macos/universal/lib/libharfbuzz.a +0 -0
  106. data/assets/macos/universal/lib/libhwy.a +0 -0
  107. data/assets/macos/universal/lib/libjpeg.a +0 -0
  108. data/assets/macos/universal/lib/libjxl.a +0 -0
  109. data/assets/macos/universal/lib/libmodplug.a +0 -0
  110. data/assets/macos/universal/lib/libmpg123.a +0 -0
  111. data/assets/macos/universal/lib/libmruby.a +0 -0
  112. data/assets/macos/universal/lib/libogg.a +0 -0
  113. data/assets/macos/universal/lib/libpng.a +0 -0
  114. data/assets/macos/universal/lib/libtiff.a +0 -0
  115. data/assets/macos/universal/lib/libvorbis.a +0 -0
  116. data/assets/macos/universal/lib/libvorbisfile.a +0 -0
  117. data/assets/macos/universal/lib/libwebp.a +0 -0
  118. data/assets/macos/universal/lib/libzstd.a +0 -0
  119. data/assets/wasm/libmruby.a +0 -0
  120. data/assets/wasm/template.html +52 -4
  121. data/assets/windows/mingw-w64-ucrt-x86_64/bin/mrbc.exe +0 -0
  122. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libFLAC.a +0 -0
  123. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libLerc.a +0 -0
  124. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libSDL2.a +0 -0
  125. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libSDL2_image.a +0 -0
  126. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libSDL2_mixer.a +0 -0
  127. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libSDL2_ttf.a +0 -0
  128. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libbrotlicommon.a +0 -0
  129. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libbrotlidec.a +0 -0
  130. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libbz2.a +0 -0
  131. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libdeflate.a +0 -0
  132. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libfreetype.a +0 -0
  133. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libglew32.a +0 -0
  134. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libgraphite2.a +0 -0
  135. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libharfbuzz.a +0 -0
  136. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libhwy.a +0 -0
  137. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libjbig.a +0 -0
  138. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libjpeg.a +0 -0
  139. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libjxl.a +0 -0
  140. data/assets/windows/mingw-w64-ucrt-x86_64/lib/liblzma.a +0 -0
  141. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libmodplug.a +0 -0
  142. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libmpg123.a +0 -0
  143. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libmruby.a +0 -0
  144. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libogg.a +0 -0
  145. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libopus.a +0 -0
  146. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libopusfile.a +0 -0
  147. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libpng.a +0 -0
  148. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libsndfile.a +0 -0
  149. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libssp.a +1 -0
  150. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libstdc++.a +0 -0
  151. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libtiff.a +0 -0
  152. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libvorbis.a +0 -0
  153. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libvorbisfile.a +0 -0
  154. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libwebp.a +0 -0
  155. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libz.a +0 -0
  156. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libzstd.a +0 -0
  157. data/assets/windows/mingw-w64-x86_64/bin/mrbc.exe +0 -0
  158. data/assets/windows/mingw-w64-x86_64/lib/libFLAC.a +0 -0
  159. data/assets/windows/mingw-w64-x86_64/lib/libLerc.a +0 -0
  160. data/assets/windows/mingw-w64-x86_64/lib/libSDL2.a +0 -0
  161. data/assets/windows/mingw-w64-x86_64/lib/libSDL2_image.a +0 -0
  162. data/assets/windows/mingw-w64-x86_64/lib/libSDL2_mixer.a +0 -0
  163. data/assets/windows/mingw-w64-x86_64/lib/libSDL2_ttf.a +0 -0
  164. data/assets/windows/mingw-w64-x86_64/lib/libbrotlicommon.a +0 -0
  165. data/assets/windows/mingw-w64-x86_64/lib/libbrotlidec.a +0 -0
  166. data/assets/windows/mingw-w64-x86_64/lib/libdeflate.a +0 -0
  167. data/assets/windows/mingw-w64-x86_64/lib/libfreetype.a +0 -0
  168. data/assets/windows/mingw-w64-x86_64/lib/libglew32.a +0 -0
  169. data/assets/windows/mingw-w64-x86_64/lib/libharfbuzz.a +0 -0
  170. data/assets/windows/mingw-w64-x86_64/lib/libhwy.a +0 -0
  171. data/assets/windows/mingw-w64-x86_64/lib/libjpeg.a +0 -0
  172. data/assets/windows/mingw-w64-x86_64/lib/libjxl.a +0 -0
  173. data/assets/windows/mingw-w64-x86_64/lib/liblzma.a +0 -0
  174. data/assets/windows/mingw-w64-x86_64/lib/libmpg123.a +0 -0
  175. data/assets/windows/mingw-w64-x86_64/lib/libmruby.a +0 -0
  176. data/assets/windows/mingw-w64-x86_64/lib/libopus.a +0 -0
  177. data/assets/windows/mingw-w64-x86_64/lib/libpng.a +0 -0
  178. data/assets/windows/mingw-w64-x86_64/lib/libsndfile.a +0 -0
  179. data/assets/windows/mingw-w64-x86_64/lib/libssp.a +0 -0
  180. data/assets/windows/mingw-w64-x86_64/lib/libstdc++.a +0 -0
  181. data/assets/windows/mingw-w64-x86_64/lib/libtiff.a +0 -0
  182. data/assets/windows/mingw-w64-x86_64/lib/libwebp.a +0 -0
  183. data/assets/windows/mingw-w64-x86_64/lib/libz.a +0 -0
  184. data/assets/windows/mingw-w64-x86_64/lib/libzstd.a +0 -0
  185. data/ext/ruby2d/canvas.c +540 -0
  186. data/ext/ruby2d/extconf.rb +39 -21
  187. data/ext/ruby2d/gl.c +3 -3
  188. data/ext/ruby2d/image.c +7 -7
  189. data/ext/ruby2d/ruby2d.c +741 -24
  190. data/ext/ruby2d/ruby2d.h +66 -3
  191. data/ext/ruby2d/sound.c +16 -2
  192. data/lib/ruby2d/canvas.rb +315 -0
  193. data/lib/ruby2d/circle.rb +30 -15
  194. data/lib/ruby2d/cli/build.rb +11 -4
  195. data/lib/ruby2d/cli/enable_console.rb +3 -1
  196. data/lib/ruby2d/color.rb +133 -77
  197. data/lib/ruby2d/core.rb +32 -0
  198. data/lib/ruby2d/dsl.rb +38 -32
  199. data/lib/ruby2d/exceptions.rb +2 -1
  200. data/lib/ruby2d/font.rb +97 -62
  201. data/lib/ruby2d/image.rb +48 -27
  202. data/lib/ruby2d/line.rb +84 -45
  203. data/lib/ruby2d/music.rb +33 -23
  204. data/lib/ruby2d/pixel.rb +10 -9
  205. data/lib/ruby2d/pixmap.rb +39 -0
  206. data/lib/ruby2d/pixmap_atlas.rb +56 -0
  207. data/lib/ruby2d/quad.rb +98 -49
  208. data/lib/ruby2d/rectangle.rb +35 -36
  209. data/lib/ruby2d/renderable.rb +7 -6
  210. data/lib/ruby2d/sound.rb +23 -17
  211. data/lib/ruby2d/sprite.rb +181 -140
  212. data/lib/ruby2d/square.rb +21 -20
  213. data/lib/ruby2d/text.rb +47 -19
  214. data/lib/ruby2d/texture.rb +13 -3
  215. data/lib/ruby2d/tileset.rb +97 -44
  216. data/lib/ruby2d/triangle.rb +91 -42
  217. data/lib/ruby2d/version.rb +3 -1
  218. data/lib/ruby2d/vertices.rb +81 -45
  219. data/lib/ruby2d/window.rb +508 -371
  220. data/lib/ruby2d.rb +11 -29
  221. metadata +84 -16
  222. data/assets/include/SDL2/SDL_config_psp.h +0 -165
  223. data/assets/include/SDL2/SDL_config_wiz.h +0 -154
  224. data/assets/include/glew.h +0 -23686
  225. data/assets/macos/universal/lib/libpng16.a +0 -0
  226. data/assets/wasm/build_config.rb +0 -13
  227. data/assets/windows/glew/README.md +0 -10
  228. data/assets/windows/glew/glew.h +0 -23686
  229. data/assets/windows/glew/libglew32.a +0 -0
  230. data/assets/windows/mingw-w64-x86_64/lib/libpng16.a +0 -0
  231. data/lib/ruby2d/entity.rb +0 -17
@@ -44,6 +44,9 @@
44
44
  #include <limits.h>
45
45
 
46
46
  #ifdef __cplusplus
47
+ #ifndef UINTPTR_MAX
48
+ #error Must be placed `#include <mruby.h>` before `#include <stdint.h>`
49
+ #endif
47
50
  #ifndef SIZE_MAX
48
51
  #ifdef __SIZE_MAX__
49
52
  #define SIZE_MAX __SIZE_MAX__
@@ -66,14 +69,18 @@
66
69
  #define mrb_assert_int_fit(t1,n,t2,max) ((void)0)
67
70
  #endif
68
71
 
69
- #if (defined __cplusplus && __cplusplus >= 201103L) || \
72
+ #if (defined __cplusplus && __cplusplus >= 201703L)
73
+ # define mrb_static_assert(...) static_assert(__VA_ARGS__)
74
+ # define mrb_static_assert1(exp) static_assert(exp)
75
+ # define mrb_static_assert2(exp, str) static_assert(exp, str)
76
+ #elif (defined __cplusplus && __cplusplus >= 201103L) || \
70
77
  (defined _MSC_VER) || \
71
78
  (defined __GXX_EXPERIMENTAL_CXX0X__) /* for old G++/Clang++ */
72
- # define mrb_static_assert(exp, str) static_assert(exp, str)
79
+ # define mrb_static_assert2(exp, str) static_assert(exp, str)
73
80
  #elif defined __STDC_VERSION__ && \
74
81
  ((__STDC_VERSION__ >= 201112L) || \
75
82
  (defined __GNUC__ && __GNUC__ * 100 + __GNUC_MINOR__ >= 406))
76
- # define mrb_static_assert(exp, str) _Static_assert(exp, str)
83
+ # define mrb_static_assert2(exp, str) _Static_assert(exp, str)
77
84
  #else
78
85
  # /* alternative implementation of static_assert() */
79
86
  # define _mrb_static_assert_cat0(a, b) a##b
@@ -83,10 +90,26 @@
83
90
  # else
84
91
  # define _mrb_static_assert_id(prefix) _mrb_static_assert_cat(prefix, __LINE__)
85
92
  # endif
86
- # define mrb_static_assert(exp, str) \
93
+ # define mrb_static_assert2(exp, str) \
87
94
  struct _mrb_static_assert_id(_mrb_static_assert_) { char x[(exp) ? 1 : -1]; }
88
95
  #endif
89
- #define mrb_static_assert1(exp) mrb_static_assert(exp, #exp)
96
+
97
+ #ifndef mrb_static_assert
98
+ # define mrb_static_assert1(exp) mrb_static_assert2(exp, #exp)
99
+ # define mrb_static_assert_expand(...) __VA_ARGS__ /* for MSVC behaviour - https://stackoverflow.com/q/5530505 */
100
+ # define mrb_static_assert_selector(a, b, name, ...) name
101
+ /**
102
+ * The `mrb_static_assert()` macro function takes one or two arguments.
103
+ *
104
+ * !!!c
105
+ * mrb_static_assert(expect_condition);
106
+ * mrb_static_assert(expect_condition, error_message);
107
+ */
108
+ # define mrb_static_assert(...) \
109
+ mrb_static_assert_expand(mrb_static_assert_selector(__VA_ARGS__, mrb_static_assert2, mrb_static_assert1, _)(__VA_ARGS__))
110
+ #endif
111
+
112
+ #define mrb_static_assert_powerof2(num) mrb_static_assert((num) > 0 && (num) == ((num) & -(num)), "need power of 2 for " #num)
90
113
 
91
114
  #include "mrbconf.h"
92
115
 
@@ -96,6 +119,7 @@
96
119
  #include <mruby/version.h>
97
120
 
98
121
  #ifndef MRB_NO_FLOAT
122
+ #include <math.h>
99
123
  #include <float.h>
100
124
  #ifndef FLT_EPSILON
101
125
  #define FLT_EPSILON (1.19209290e-07f)
@@ -149,9 +173,10 @@ typedef void* (*mrb_allocf) (struct mrb_state *mrb, void*, size_t, void *ud);
149
173
  #endif
150
174
 
151
175
  typedef struct {
176
+ uint8_t n:4; /* (15=*) c=n|nk<<4 */
177
+ uint8_t nk:4; /* (15=*) */
178
+ uint8_t cci; /* called from C function */
152
179
  mrb_sym mid;
153
- int16_t argc;
154
- int16_t acc;
155
180
  const struct RProc *proc;
156
181
  mrb_value *stack;
157
182
  const mrb_code *pc; /* current address on iseq of this proc */
@@ -185,6 +210,7 @@ struct mrb_context {
185
210
 
186
211
  #ifdef MRB_METHOD_CACHE_SIZE
187
212
  # undef MRB_NO_METHOD_CACHE
213
+ mrb_static_assert_powerof2(MRB_METHOD_CACHE_SIZE);
188
214
  #else
189
215
  /* default method cache size: 256 */
190
216
  /* cache size needs to be power of 2 */
@@ -265,7 +291,9 @@ typedef struct mrb_state {
265
291
  #endif
266
292
 
267
293
  mrb_sym symidx;
268
- struct symbol_name *symtbl; /* symbol table */
294
+ const char **symtbl;
295
+ uint8_t *symlink;
296
+ uint8_t *symflags;
269
297
  mrb_sym symhash[256];
270
298
  size_t symcapa;
271
299
  #ifndef MRB_USE_ALL_SYMBOLS
@@ -886,19 +914,20 @@ MRB_API struct RClass* mrb_define_module_under_id(mrb_state *mrb, struct RClass
886
914
  * | char | Ruby type | C types | Notes |
887
915
  * |:----:|----------------|-------------------|----------------------------------------------------|
888
916
  * | `o` | {Object} | {mrb_value} | Could be used to retrieve any type of argument |
889
- * | `C` | {Class}/{Module} | {mrb_value} | |
917
+ * | `C` | {Class}/{Module} | {mrb_value} | when `!` follows, the value may be `nil` |
890
918
  * | `S` | {String} | {mrb_value} | when `!` follows, the value may be `nil` |
891
919
  * | `A` | {Array} | {mrb_value} | when `!` follows, the value may be `nil` |
892
920
  * | `H` | {Hash} | {mrb_value} | when `!` follows, the value may be `nil` |
893
921
  * | `s` | {String} | const char *, {mrb_int} | Receive two arguments; `s!` gives (`NULL`,`0`) for `nil` |
894
922
  * | `z` | {String} | const char * | `NULL` terminated string; `z!` gives `NULL` for `nil` |
895
923
  * | `a` | {Array} | const {mrb_value} *, {mrb_int} | Receive two arguments; `a!` gives (`NULL`,`0`) for `nil` |
924
+ * | `c` | {Class}/{Module} | strcut RClass * | `c!` gives `NULL` for `nil` |
896
925
  * | `f` | {Integer}/{Float} | {mrb_float} | |
897
926
  * | `i` | {Integer}/{Float} | {mrb_int} | |
898
927
  * | `b` | boolean | {mrb_bool} | |
899
928
  * | `n` | {String}/{Symbol} | {mrb_sym} | |
900
929
  * | `d` | data | void *, {mrb_data_type} const | 2nd argument will be used to check data type so it won't be modified; when `!` follows, the value may be `nil` |
901
- * | `I` | inline struct | void * | |
930
+ * | `I` | inline struct | void *, struct RClass | `I!` gives `NULL` for `nil` |
902
931
  * | `&` | block | {mrb_value} | &! raises exception if no block given. |
903
932
  * | `*` | rest arguments | const {mrb_value} *, {mrb_int} | Receive the rest of arguments as an array; `*!` avoid copy of the stack. |
904
933
  * | <code>\|</code> | optional | | After this spec following specs would be optional. |
@@ -906,6 +935,13 @@ MRB_API struct RClass* mrb_define_module_under_id(mrb_state *mrb, struct RClass
906
935
  * | `:` | keyword args | {mrb_kwargs} const | Get keyword arguments. @see mrb_kwargs |
907
936
  *
908
937
  * @see mrb_get_args
938
+ *
939
+ * Immediately after format specifiers it can add format modifiers:
940
+ *
941
+ * | char | Notes |
942
+ * |:----:|-----------------------------------------------------------------------------------------|
943
+ * | `!` | Switch to the alternate mode; The behaviour changes depending on the format specifier |
944
+ * | `+` | Request a not frozen object; However, except nil value |
909
945
  */
910
946
  typedef const char *mrb_args_format;
911
947
 
@@ -1004,6 +1040,11 @@ MRB_API const mrb_value *mrb_get_argv(mrb_state *mrb);
1004
1040
  */
1005
1041
  MRB_API mrb_value mrb_get_arg1(mrb_state *mrb);
1006
1042
 
1043
+ /**
1044
+ * Check if a block argument is given from mrb_state.
1045
+ */
1046
+ MRB_API mrb_bool mrb_block_given_p(mrb_state *mrb);
1047
+
1007
1048
  /* `strlen` for character string literals (use with caution or `strlen` instead)
1008
1049
  Adjacent string literals are concatenated in C/C++ in translation phase 6.
1009
1050
  If `lit` is not one, the compiler will report a syntax error:
@@ -1126,6 +1167,17 @@ MRB_API void *mrb_malloc_simple(mrb_state*, size_t); /* return NULL if no memor
1126
1167
  MRB_API struct RBasic *mrb_obj_alloc(mrb_state*, enum mrb_vtype, struct RClass*);
1127
1168
  MRB_API void mrb_free(mrb_state*, void*);
1128
1169
 
1170
+ /**
1171
+ * Allocates a Ruby object that matches the constant literal defined in
1172
+ * `enum mrb_vtype` and returns a pointer to the corresponding C type.
1173
+ *
1174
+ * @param mrb The current mruby state
1175
+ * @param tt The constant literal of `enum mrb_vtype`
1176
+ * @param klass A Class object
1177
+ * @return Reference to the newly created object
1178
+ */
1179
+ #define MRB_OBJ_ALLOC(mrb, tt, klass) ((MRB_VTYPE_TYPEOF(tt)*)mrb_obj_alloc(mrb, tt, klass))
1180
+
1129
1181
  MRB_API mrb_value mrb_str_new(mrb_state *mrb, const char *p, size_t len);
1130
1182
 
1131
1183
  /**
@@ -1219,10 +1271,11 @@ MRB_API mrb_sym mrb_obj_to_sym(mrb_state *mrb, mrb_value name);
1219
1271
  MRB_API mrb_bool mrb_obj_eq(mrb_state *mrb, mrb_value a, mrb_value b);
1220
1272
  MRB_API mrb_bool mrb_obj_equal(mrb_state *mrb, mrb_value a, mrb_value b);
1221
1273
  MRB_API mrb_bool mrb_equal(mrb_state *mrb, mrb_value obj1, mrb_value obj2);
1222
- MRB_API mrb_value mrb_convert_to_integer(mrb_state *mrb, mrb_value val, mrb_int base);
1223
- MRB_API mrb_value mrb_Integer(mrb_state *mrb, mrb_value val);
1224
1274
  #ifndef MRB_NO_FLOAT
1225
- MRB_API mrb_value mrb_Float(mrb_state *mrb, mrb_value val);
1275
+ MRB_API mrb_value mrb_ensure_float_type(mrb_state *mrb, mrb_value val);
1276
+ #define mrb_as_float(mrb, x) mrb_float(mrb_ensure_float_type(mrb, x))
1277
+ /* obsolete: use mrb_ensure_float_type() instead */
1278
+ #define mrb_to_float(mrb, val) mrb_ensure_float_type(mrb, val)
1226
1279
  #endif
1227
1280
  MRB_API mrb_value mrb_inspect(mrb_state *mrb, mrb_value obj);
1228
1281
  MRB_API mrb_bool mrb_eql(mrb_state *mrb, mrb_value obj1, mrb_value obj2);
@@ -1339,10 +1392,25 @@ MRB_API void mrb_gc_register(mrb_state *mrb, mrb_value obj);
1339
1392
  /* mrb_gc_unregister() removes the object from GC root. */
1340
1393
  MRB_API void mrb_gc_unregister(mrb_state *mrb, mrb_value obj);
1341
1394
 
1342
- MRB_API mrb_value mrb_to_int(mrb_state *mrb, mrb_value val);
1343
- #define mrb_int(mrb, val) mrb_integer(mrb_to_int(mrb, val))
1395
+ /* type conversion/check functions */
1396
+ MRB_API mrb_value mrb_ensure_array_type(mrb_state *mrb, mrb_value self);
1397
+ MRB_API mrb_value mrb_check_array_type(mrb_state *mrb, mrb_value self);
1398
+ MRB_API mrb_value mrb_ensure_hash_type(mrb_state *mrb, mrb_value hash);
1399
+ MRB_API mrb_value mrb_check_hash_type(mrb_state *mrb, mrb_value hash);
1400
+ MRB_API mrb_value mrb_ensure_string_type(mrb_state *mrb, mrb_value str);
1401
+ MRB_API mrb_value mrb_check_string_type(mrb_state *mrb, mrb_value str);
1402
+ /* obsolete: use mrb_ensure_string_type() instead */
1403
+ #define mrb_string_type(mrb, str) mrb_ensure_string_type(mrb,str)
1404
+ #define mrb_to_str(mrb, str) mrb_ensure_string_type(mrb,str)
1405
+ /* obsolete: use mrb_obj_as_string() instead */
1406
+ #define mrb_str_to_str(mrb, str) mrb_obj_as_string(mrb, str)
1407
+ MRB_API mrb_value mrb_ensure_int_type(mrb_state *mrb, mrb_value val);
1408
+ #define mrb_as_int(mrb, val) mrb_integer(mrb_ensure_int_type(mrb, val))
1409
+ /* obsolete: use mrb_ensure_int_type() instead */
1410
+ #define mrb_to_integer(mrb, val) mrb_ensure_int_type(mrb, val)
1411
+ #define mrb_to_int(mrb, val) mrb_ensure_int_type(mrb, val)
1412
+
1344
1413
  /* string type checking (contrary to the name, it doesn't convert) */
1345
- MRB_API mrb_value mrb_to_str(mrb_state *mrb, mrb_value val);
1346
1414
  MRB_API void mrb_check_type(mrb_state *mrb, mrb_value x, enum mrb_vtype t);
1347
1415
 
1348
1416
  MRB_INLINE void mrb_check_frozen(mrb_state *mrb, void *o)
@@ -1361,6 +1429,8 @@ MRB_API mrb_bool mrb_respond_to(mrb_state *mrb, mrb_value obj, mrb_sym mid);
1361
1429
  MRB_API mrb_bool mrb_obj_is_instance_of(mrb_state *mrb, mrb_value obj, struct RClass* c);
1362
1430
  MRB_API mrb_bool mrb_func_basic_p(mrb_state *mrb, mrb_value obj, mrb_sym mid, mrb_func_t func);
1363
1431
 
1432
+ /* obsolete function(s); will be removed */
1433
+ #define mrb_int(mrb, val) mrb_as_int(mrb, val)
1364
1434
 
1365
1435
  /**
1366
1436
  * Resume a Fiber
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -2,16 +2,64 @@
2
2
  <html lang="en" dir="ltr">
3
3
  <head>
4
4
  <meta charset="utf-8">
5
- <title>Ruby on WebAssembly</title>
5
+ <title>Ruby 2D</title>
6
6
  <style>
7
7
  body {
8
8
  font-family: system-ui;
9
9
  }
10
+
11
+ hr {
12
+ border: none;
13
+ height: 3px;
14
+ margin: 15px 0;
15
+ background-color: lightgray;
16
+ }
17
+
18
+ #canvas {
19
+ display: block;
20
+ margin: 0 auto;
21
+ }
22
+
23
+ #output {
24
+ display: block;
25
+ box-sizing: border-box;
26
+ width: 100%;
27
+ height: 300px;
28
+ padding: 10px;
29
+ font-size: 14px;
30
+ font-family: monospace;
31
+ color: white;
32
+ border: none;
33
+ background-color: black;
34
+ }
10
35
  </style>
11
36
  </head>
12
37
  <body>
13
- <h1>Ruby on WebAssembly</h1>
14
- <p>Open the web console to see output and errors.</p>
38
+ <h1>Ruby 2D</h1>
39
+ <p>This is a sample HTML template, but you can create your own!</p>
40
+ <hr>
41
+ <canvas id="canvas" oncontextmenu=".preventDefault()"></canvas>
42
+ <h2 style="margin-bottom: 0;">Output</h2>
43
+ <p style="margin: 4px 0 8px 0">Open the JavaScript console in developer tools for more detail.</p>
44
+ <textarea id="output"></textarea>
15
45
  </body>
16
- <script src="app.js"></script>
46
+
47
+ <script>
48
+ var Module = {
49
+ canvas: (function() { return document.getElementById('canvas'); })(),
50
+ print: (function() {
51
+ var element = document.getElementById('output');
52
+ if (element) element.value = ''; // clear browser cache
53
+ return function(text) {
54
+ if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
55
+ console.log(text);
56
+ if (element) {
57
+ element.value += text + "\n";
58
+ element.scrollTop = element.scrollHeight; // focus on bottom
59
+ }
60
+ };
61
+ })()
62
+ };
63
+ </script>
64
+ <script async src="app.js"></script>
17
65
  </html>
@@ -0,0 +1 @@
1
+ !<arch>