ruby2d 0.11.1 → 0.11.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/assets/include/SDL2/SDL.h +108 -14
- data/assets/include/SDL2/SDL_assert.h +81 -50
- data/assets/include/SDL2/SDL_atomic.h +135 -35
- data/assets/include/SDL2/SDL_audio.h +960 -355
- data/assets/include/SDL2/SDL_bits.h +11 -6
- data/assets/include/SDL2/SDL_blendmode.h +91 -14
- data/assets/include/SDL2/SDL_clipboard.h +30 -7
- data/assets/include/SDL2/SDL_config.h +3 -1
- data/assets/include/SDL2/SDL_config_android.h +11 -1
- data/assets/include/SDL2/SDL_config_emscripten.h +216 -0
- data/assets/include/SDL2/SDL_config_iphoneos.h +9 -1
- data/assets/include/SDL2/SDL_config_macosx.h +16 -2
- data/assets/include/SDL2/SDL_config_minimal.h +4 -1
- data/assets/include/SDL2/SDL_config_os2.h +37 -20
- data/assets/include/SDL2/SDL_config_pandora.h +6 -1
- data/assets/include/SDL2/SDL_config_psp.h +8 -8
- data/assets/include/SDL2/SDL_config_windows.h +39 -22
- data/assets/include/SDL2/SDL_config_winrt.h +23 -8
- data/assets/include/SDL2/SDL_config_wiz.h +6 -1
- data/assets/include/SDL2/SDL_copying.h +1 -1
- data/assets/include/SDL2/SDL_cpuinfo.h +331 -71
- data/assets/include/SDL2/SDL_egl.h +906 -280
- data/assets/include/SDL2/SDL_endian.h +101 -47
- data/assets/include/SDL2/SDL_error.h +70 -19
- data/assets/include/SDL2/SDL_events.h +387 -79
- data/assets/include/SDL2/SDL_filesystem.h +73 -64
- data/assets/include/SDL2/SDL_gamecontroller.h +585 -125
- data/assets/include/SDL2/SDL_gesture.h +36 -6
- data/assets/include/SDL2/SDL_haptic.h +304 -210
- data/assets/include/SDL2/SDL_hidapi.h +451 -0
- data/assets/include/SDL2/SDL_hints.h +1286 -897
- data/assets/include/SDL2/SDL_joystick.h +577 -130
- data/assets/include/SDL2/SDL_keyboard.h +162 -63
- data/assets/include/SDL2/SDL_keycode.h +7 -5
- data/assets/include/SDL2/SDL_loadso.h +42 -8
- data/assets/include/SDL2/SDL_locale.h +34 -32
- data/assets/include/SDL2/SDL_log.h +212 -19
- data/assets/include/SDL2/SDL_main.h +72 -17
- data/assets/include/SDL2/SDL_messagebox.h +70 -23
- data/assets/include/SDL2/SDL_metal.h +27 -32
- data/assets/include/SDL2/SDL_misc.h +19 -15
- data/assets/include/SDL2/SDL_mouse.h +262 -110
- data/assets/include/SDL2/SDL_mutex.h +286 -66
- data/assets/include/SDL2/SDL_name.h +1 -1
- data/assets/include/SDL2/SDL_opengl.h +1 -1
- data/assets/include/SDL2/SDL_opengles.h +1 -1
- data/assets/include/SDL2/SDL_opengles2.h +2 -2
- data/assets/include/SDL2/SDL_pixels.h +199 -34
- data/assets/include/SDL2/SDL_platform.h +39 -2
- data/assets/include/SDL2/SDL_power.h +23 -10
- data/assets/include/SDL2/SDL_quit.h +1 -1
- data/assets/include/SDL2/SDL_rect.h +78 -28
- data/assets/include/SDL2/SDL_render.h +1204 -472
- data/assets/include/SDL2/SDL_revision.h +2 -2
- data/assets/include/SDL2/SDL_rwops.h +605 -33
- data/assets/include/SDL2/SDL_scancode.h +1 -1
- data/assets/include/SDL2/SDL_sensor.h +76 -42
- data/assets/include/SDL2/SDL_shape.h +38 -27
- data/assets/include/SDL2/SDL_stdinc.h +96 -24
- data/assets/include/SDL2/SDL_surface.h +571 -139
- data/assets/include/SDL2/SDL_system.h +339 -101
- data/assets/include/SDL2/SDL_syswm.h +50 -20
- data/assets/include/SDL2/SDL_test.h +1 -1
- data/assets/include/SDL2/SDL_test_assert.h +2 -2
- data/assets/include/SDL2/SDL_test_common.h +23 -6
- data/assets/include/SDL2/SDL_test_compare.h +1 -1
- data/assets/include/SDL2/SDL_test_crc32.h +1 -1
- data/assets/include/SDL2/SDL_test_font.h +3 -3
- data/assets/include/SDL2/SDL_test_fuzzer.h +28 -26
- data/assets/include/SDL2/SDL_test_harness.h +6 -6
- data/assets/include/SDL2/SDL_test_images.h +1 -1
- data/assets/include/SDL2/SDL_test_log.h +1 -1
- data/assets/include/SDL2/SDL_test_md5.h +1 -1
- data/assets/include/SDL2/SDL_test_memory.h +1 -1
- data/assets/include/SDL2/SDL_test_random.h +2 -2
- data/assets/include/SDL2/SDL_thread.h +226 -128
- data/assets/include/SDL2/SDL_timer.h +129 -22
- data/assets/include/SDL2/SDL_touch.h +48 -8
- data/assets/include/SDL2/SDL_ttf.h +102 -9
- data/assets/include/SDL2/SDL_types.h +1 -1
- data/assets/include/SDL2/SDL_version.h +72 -46
- data/assets/include/SDL2/SDL_video.h +1266 -460
- data/assets/include/SDL2/SDL_vulkan.h +100 -161
- data/assets/include/SDL2/begin_code.h +22 -1
- data/assets/include/SDL2/close_code.h +1 -1
- data/assets/include/mrbconf.h +234 -0
- data/assets/include/mruby/array.h +317 -0
- data/assets/include/mruby/boxing_nan.h +130 -0
- data/assets/include/mruby/boxing_no.h +58 -0
- data/assets/include/mruby/boxing_word.h +205 -0
- data/assets/include/mruby/class.h +108 -0
- data/assets/include/mruby/common.h +92 -0
- data/assets/include/mruby/compile.h +210 -0
- data/assets/include/mruby/data.h +76 -0
- data/assets/include/mruby/debug.h +66 -0
- data/assets/include/mruby/dump.h +158 -0
- data/assets/include/mruby/endian.h +44 -0
- data/assets/include/mruby/error.h +137 -0
- data/assets/include/mruby/gc.h +92 -0
- data/assets/include/mruby/hash.h +242 -0
- data/assets/include/mruby/irep.h +147 -0
- data/assets/include/mruby/istruct.h +50 -0
- data/assets/include/mruby/khash.h +284 -0
- data/assets/include/mruby/numeric.h +169 -0
- data/assets/include/mruby/object.h +43 -0
- data/assets/include/mruby/opcode.h +43 -0
- data/assets/include/mruby/ops.h +122 -0
- data/assets/include/mruby/presym/disable.h +70 -0
- data/assets/include/mruby/presym/enable.h +37 -0
- data/assets/include/mruby/presym/scanning.h +73 -0
- data/assets/include/mruby/presym.h +40 -0
- data/assets/include/mruby/proc.h +209 -0
- data/assets/include/mruby/range.h +79 -0
- data/assets/include/mruby/re.h +16 -0
- data/assets/include/mruby/string.h +469 -0
- data/assets/include/mruby/throw.h +66 -0
- data/assets/include/mruby/value.h +400 -0
- data/assets/include/mruby/variable.h +140 -0
- data/assets/include/mruby/version.h +143 -0
- data/assets/include/mruby.h +1444 -0
- data/assets/macos/universal/bin/mrbc +0 -0
- data/assets/macos/universal/lib/libFLAC.a +0 -0
- data/assets/macos/universal/lib/libSDL2.a +0 -0
- data/assets/macos/universal/lib/libSDL2_image.a +0 -0
- data/assets/macos/{lib → universal/lib}/libSDL2_mixer.a +0 -0
- data/assets/macos/universal/lib/libSDL2_ttf.a +0 -0
- data/assets/macos/universal/lib/libfreetype.a +0 -0
- data/assets/macos/universal/lib/libgraphite2.a +0 -0
- data/assets/macos/universal/lib/libharfbuzz.a +0 -0
- data/assets/macos/universal/lib/libjpeg.a +0 -0
- data/assets/macos/{lib → universal/lib}/libmodplug.a +0 -0
- data/assets/macos/{lib → universal/lib}/libmpg123.a +0 -0
- data/assets/{mingw/lib/libSDL2.a → macos/universal/lib/libmruby.a} +0 -0
- data/assets/macos/{lib → universal/lib}/libogg.a +0 -0
- data/assets/macos/universal/lib/libpng16.a +0 -0
- data/assets/macos/universal/lib/libtiff.a +0 -0
- data/assets/macos/universal/lib/libvorbis.a +0 -0
- data/assets/macos/universal/lib/libvorbisfile.a +0 -0
- data/assets/macos/universal/lib/libwebp.a +0 -0
- data/assets/test_media/README.md +3 -0
- data/assets/test_media/bitstream_vera/COPYRIGHT.txt +124 -0
- data/assets/test_media/bitstream_vera/vera.ttf +0 -0
- data/assets/test_media/boom.png +0 -0
- data/assets/test_media/coin.png +0 -0
- data/assets/test_media/colors.png +0 -0
- data/assets/test_media/controller.png +0 -0
- data/assets/test_media/dial.wav +0 -0
- data/assets/test_media/hero.png +0 -0
- data/assets/test_media/image.bmp +0 -0
- data/assets/test_media/image.jpg +0 -0
- data/assets/test_media/image.png +0 -0
- data/assets/test_media/music.flac +0 -0
- data/assets/test_media/music.mp3 +0 -0
- data/assets/test_media/music.ogg +0 -0
- data/assets/test_media/music.wav +0 -0
- data/assets/test_media/originals/boom.pxm +0 -0
- data/assets/test_media/originals/coin.pxm +0 -0
- data/assets/test_media/originals/controller.sketch +0 -0
- data/assets/test_media/originals/hero.pxm +0 -0
- data/assets/test_media/originals/image.pxm +0 -0
- data/assets/test_media/originals/music.caf +0 -0
- data/assets/test_media/originals/texture_atlas.pxm +0 -0
- data/assets/test_media/rondo_alla_turka.ogg +0 -0
- data/assets/test_media/sound.flac +0 -0
- data/assets/test_media/sound.mp3 +0 -0
- data/assets/test_media/sound.ogg +0 -0
- data/assets/test_media/sound.wav +0 -0
- data/assets/test_media/sprite_sheet.png +0 -0
- data/assets/test_media/texture_atlas.png +0 -0
- data/assets/wasm/build_config.rb +13 -0
- data/assets/wasm/libmruby.a +0 -0
- data/assets/wasm/template.html +17 -0
- data/assets/windows/glew/README.md +10 -0
- data/assets/windows/glew/glew.h +23686 -0
- data/assets/{mingw/lib → windows/glew}/libglew32.a +0 -0
- data/assets/windows/mingw-w64-x86_64/bin/mrbc.exe +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libFLAC.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libLerc.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libSDL2.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libSDL2_image.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libSDL2_mixer.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libSDL2_ttf.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libbrotlicommon.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libbrotlidec.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libbz2.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libdeflate.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libfreetype.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libglew32.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libgraphite2.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libharfbuzz.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libjbig.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libjpeg.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/liblzma.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libmodplug.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libmpg123.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libmruby.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libogg.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libopus.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libopusfile.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libpng16.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libsndfile.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libssp.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libstdc++.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libtiff.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libvorbis.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libvorbisfile.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libwebp.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libz.a +0 -0
- data/assets/windows/mingw-w64-x86_64/lib/libzstd.a +0 -0
- data/assets/{ios → xcode/ios}/Assets.xcassets/AppIcon.appiconset/Contents.json +0 -0
- data/assets/{ios → xcode/ios}/Assets.xcassets/Contents.json +0 -0
- data/assets/{ios → xcode/ios}/Base.lproj/LaunchScreen.storyboard +0 -0
- data/assets/{ios → xcode/ios}/Info.plist +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mrbconf.h +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/array.h +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/boxing_nan.h +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/boxing_no.h +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/boxing_word.h +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/class.h +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/common.h +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/compile.h +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/data.h +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/debug.h +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/dump.h +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/error.h +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/gc.h +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/hash.h +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/irep.h +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/istruct.h +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/khash.h +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/numeric.h +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/object.h +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/opcode.h +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/ops.h +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/proc.h +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/range.h +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/re.h +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/string.h +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/throw.h +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/value.h +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/variable.h +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby/version.h +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Headers/mruby.h +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/Info.plist +0 -0
- data/assets/{ios → xcode/ios}/MRuby.framework/MRuby +0 -0
- data/assets/{ios → xcode/ios}/MyApp.xcodeproj/project.pbxproj +0 -0
- data/assets/{ios → xcode/ios}/MyApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -0
- data/assets/{ios → xcode/ios}/MyApp.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -0
- data/assets/{ios → xcode/ios}/MyApp.xcodeproj/project.xcworkspace/xcshareddata/MyApp.xcscmblueprint +0 -0
- data/assets/{ios → xcode/ios}/main.c +0 -0
- data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Content.imageset/Contents.json +0 -0
- data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Contents.json +0 -0
- data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Contents.json +0 -0
- data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Content.imageset/Contents.json +0 -0
- data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Contents.json +0 -0
- data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json +0 -0
- data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Contents.json +0 -0
- data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Content.imageset/Contents.json +0 -0
- data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Contents.json +0 -0
- data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Contents.json +0 -0
- data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Content.imageset/Contents.json +0 -0
- data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Contents.json +0 -0
- data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json +0 -0
- data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Contents.json +0 -0
- data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Contents.json +0 -0
- data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Top Shelf Image Wide.imageset/Contents.json +0 -0
- data/assets/{tvos → xcode/tvos}/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Top Shelf Image.imageset/Contents.json +0 -0
- data/assets/{tvos → xcode/tvos}/Assets.xcassets/Contents.json +0 -0
- data/assets/{tvos → xcode/tvos}/Assets.xcassets/LaunchImage.launchimage/Contents.json +0 -0
- data/assets/{tvos → xcode/tvos}/Info.plist +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mrbconf.h +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/array.h +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/boxing_nan.h +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/boxing_no.h +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/boxing_word.h +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/class.h +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/common.h +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/compile.h +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/data.h +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/debug.h +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/dump.h +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/error.h +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/gc.h +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/hash.h +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/irep.h +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/istruct.h +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/khash.h +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/numeric.h +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/object.h +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/opcode.h +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/ops.h +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/proc.h +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/range.h +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/re.h +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/string.h +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/throw.h +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/value.h +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/variable.h +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby/version.h +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Headers/mruby.h +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/Info.plist +0 -0
- data/assets/{tvos → xcode/tvos}/MRuby.framework/MRuby +0 -0
- data/assets/{tvos → xcode/tvos}/MyApp.xcodeproj/project.pbxproj +0 -0
- data/assets/{tvos → xcode/tvos}/MyApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -0
- data/assets/{tvos → xcode/tvos}/MyApp.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -0
- data/assets/{tvos → xcode/tvos}/MyApp.xcodeproj/project.xcworkspace/xcshareddata/MyApp.xcscmblueprint +0 -0
- data/assets/{tvos → xcode/tvos}/main.c +0 -0
- data/bin/ruby2d +3 -4
- data/ext/ruby2d/extconf.rb +39 -25
- data/ext/ruby2d/gl.c +1 -1
- data/ext/ruby2d/gl3.c +0 -1
- data/ext/ruby2d/gles.c +137 -84
- data/ext/ruby2d/ruby2d.c +126 -32
- data/ext/ruby2d/ruby2d.h +53 -6
- data/ext/ruby2d/text.c +14 -1
- data/ext/ruby2d/window.c +253 -215
- data/lib/ruby2d/cli/build.rb +237 -59
- data/lib/ruby2d/cli/colorize.rb +5 -4
- data/lib/ruby2d/cli/platform.rb +17 -0
- data/lib/ruby2d/font.rb +7 -1
- data/lib/ruby2d/sprite.rb +7 -2
- data/lib/ruby2d/text.rb +1 -3
- data/lib/ruby2d/texture.rb +21 -21
- data/lib/ruby2d/tileset.rb +34 -33
- data/lib/ruby2d/version.rb +1 -1
- data/lib/ruby2d/vertices.rb +11 -6
- data/lib/ruby2d.rb +14 -20
- metadata +246 -152
- data/assets/README.md +0 -22
- data/assets/Rakefile +0 -85
- data/assets/macos/lib/libFLAC.a +0 -0
- data/assets/macos/lib/libSDL2.a +0 -0
- data/assets/macos/lib/libSDL2_image.a +0 -0
- data/assets/macos/lib/libSDL2_ttf.a +0 -0
- data/assets/macos/lib/libfreetype.a +0 -0
- data/assets/macos/lib/libjpeg.a +0 -0
- data/assets/macos/lib/libpng16.a +0 -0
- data/assets/macos/lib/libtiff.a +0 -0
- data/assets/macos/lib/libvorbis.a +0 -0
- data/assets/macos/lib/libvorbisfile.a +0 -0
- data/assets/macos/lib/libwebp.a +0 -0
- data/assets/mingw/bin/SDL2.dll +0 -0
- data/assets/mingw/bin/SDL2_image.dll +0 -0
- data/assets/mingw/bin/SDL2_mixer.dll +0 -0
- data/assets/mingw/bin/SDL2_ttf.dll +0 -0
- data/assets/mingw/bin/glew32.dll +0 -0
- data/assets/mingw/bin/libFLAC-8.dll +0 -0
- data/assets/mingw/bin/libfreetype-6.dll +0 -0
- data/assets/mingw/bin/libjpeg-9.dll +0 -0
- data/assets/mingw/bin/libmodplug-1.dll +0 -0
- data/assets/mingw/bin/libmpg123-0.dll +0 -0
- data/assets/mingw/bin/libogg-0.dll +0 -0
- data/assets/mingw/bin/libopus-0.dll +0 -0
- data/assets/mingw/bin/libopusfile-0.dll +0 -0
- data/assets/mingw/bin/libpng16-16.dll +0 -0
- data/assets/mingw/bin/libtiff-5.dll +0 -0
- data/assets/mingw/bin/libvorbis-0.dll +0 -0
- data/assets/mingw/bin/libvorbisfile-3.dll +0 -0
- data/assets/mingw/bin/libwebp-7.dll +0 -0
- data/assets/mingw/bin/zlib1.dll +0 -0
- data/assets/mingw/lib/libSDL2.dll.a +0 -0
- data/assets/mingw/lib/libSDL2_image.a +0 -0
- data/assets/mingw/lib/libSDL2_image.dll.a +0 -0
- data/assets/mingw/lib/libSDL2_mixer.a +0 -0
- data/assets/mingw/lib/libSDL2_mixer.dll.a +0 -0
- data/assets/mingw/lib/libSDL2_test.a +0 -0
- data/assets/mingw/lib/libSDL2_ttf.a +0 -0
- data/assets/mingw/lib/libSDL2_ttf.dll.a +0 -0
- data/assets/mingw/lib/libSDL2main.a +0 -0
- data/assets/mingw/lib/libglew32.dll.a +0 -0
@@ -0,0 +1,1444 @@
|
|
1
|
+
/*
|
2
|
+
** mruby - An embeddable Ruby implementation
|
3
|
+
**
|
4
|
+
** Copyright (c) mruby developers 2010-2021
|
5
|
+
**
|
6
|
+
** Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
** a copy of this software and associated documentation files (the
|
8
|
+
** "Software"), to deal in the Software without restriction, including
|
9
|
+
** without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
** distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
** permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
** the following conditions:
|
13
|
+
**
|
14
|
+
** The above copyright notice and this permission notice shall be
|
15
|
+
** included in all copies or substantial portions of the Software.
|
16
|
+
**
|
17
|
+
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
20
|
+
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
21
|
+
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
22
|
+
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
23
|
+
** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
**
|
25
|
+
** [ MIT license: https://www.opensource.org/licenses/mit-license.php ]
|
26
|
+
*/
|
27
|
+
|
28
|
+
/**
|
29
|
+
* @file mruby.h
|
30
|
+
*/
|
31
|
+
|
32
|
+
#ifndef MRUBY_H
|
33
|
+
#define MRUBY_H
|
34
|
+
|
35
|
+
#ifdef __cplusplus
|
36
|
+
#define __STDC_LIMIT_MACROS
|
37
|
+
#define __STDC_CONSTANT_MACROS
|
38
|
+
#define __STDC_FORMAT_MACROS
|
39
|
+
#endif
|
40
|
+
|
41
|
+
#include <stdarg.h>
|
42
|
+
#include <stdint.h>
|
43
|
+
#include <stddef.h>
|
44
|
+
#include <limits.h>
|
45
|
+
|
46
|
+
#ifdef __cplusplus
|
47
|
+
#ifndef SIZE_MAX
|
48
|
+
#ifdef __SIZE_MAX__
|
49
|
+
#define SIZE_MAX __SIZE_MAX__
|
50
|
+
#else
|
51
|
+
#define SIZE_MAX std::numeric_limits<size_t>::max()
|
52
|
+
#endif
|
53
|
+
#endif
|
54
|
+
#endif
|
55
|
+
|
56
|
+
#ifdef _MSC_VER
|
57
|
+
# define __func__ __FUNCTION__
|
58
|
+
#endif
|
59
|
+
|
60
|
+
#ifdef MRB_DEBUG
|
61
|
+
#include <assert.h>
|
62
|
+
#define mrb_assert(p) assert(p)
|
63
|
+
#define mrb_assert_int_fit(t1,n,t2,max) assert((n)>=0 && ((sizeof(n)<=sizeof(t2))||(n<=(t1)(max))))
|
64
|
+
#else
|
65
|
+
#define mrb_assert(p) ((void)0)
|
66
|
+
#define mrb_assert_int_fit(t1,n,t2,max) ((void)0)
|
67
|
+
#endif
|
68
|
+
|
69
|
+
#if (defined __cplusplus && __cplusplus >= 201103L) || \
|
70
|
+
(defined _MSC_VER) || \
|
71
|
+
(defined __GXX_EXPERIMENTAL_CXX0X__) /* for old G++/Clang++ */
|
72
|
+
# define mrb_static_assert(exp, str) static_assert(exp, str)
|
73
|
+
#elif defined __STDC_VERSION__ && \
|
74
|
+
((__STDC_VERSION__ >= 201112L) || \
|
75
|
+
(defined __GNUC__ && __GNUC__ * 100 + __GNUC_MINOR__ >= 406))
|
76
|
+
# define mrb_static_assert(exp, str) _Static_assert(exp, str)
|
77
|
+
#else
|
78
|
+
# /* alternative implementation of static_assert() */
|
79
|
+
# define _mrb_static_assert_cat0(a, b) a##b
|
80
|
+
# define _mrb_static_assert_cat(a, b) _mrb_static_assert_cat0(a, b)
|
81
|
+
# ifdef __COUNTER__
|
82
|
+
# define _mrb_static_assert_id(prefix) _mrb_static_assert_cat(prefix, __COUNTER__)
|
83
|
+
# else
|
84
|
+
# define _mrb_static_assert_id(prefix) _mrb_static_assert_cat(prefix, __LINE__)
|
85
|
+
# endif
|
86
|
+
# define mrb_static_assert(exp, str) \
|
87
|
+
struct _mrb_static_assert_id(_mrb_static_assert_) { char x[(exp) ? 1 : -1]; }
|
88
|
+
#endif
|
89
|
+
#define mrb_static_assert1(exp) mrb_static_assert(exp, #exp)
|
90
|
+
|
91
|
+
#include "mrbconf.h"
|
92
|
+
|
93
|
+
#include <mruby/common.h>
|
94
|
+
#include <mruby/value.h>
|
95
|
+
#include <mruby/gc.h>
|
96
|
+
#include <mruby/version.h>
|
97
|
+
|
98
|
+
#ifndef MRB_NO_FLOAT
|
99
|
+
#include <float.h>
|
100
|
+
#ifndef FLT_EPSILON
|
101
|
+
#define FLT_EPSILON (1.19209290e-07f)
|
102
|
+
#endif
|
103
|
+
#ifndef DBL_EPSILON
|
104
|
+
#define DBL_EPSILON ((double)2.22044604925031308085e-16L)
|
105
|
+
#endif
|
106
|
+
#ifndef LDBL_EPSILON
|
107
|
+
#define LDBL_EPSILON (1.08420217248550443401e-19L)
|
108
|
+
#endif
|
109
|
+
|
110
|
+
#ifdef MRB_USE_FLOAT32
|
111
|
+
#define MRB_FLOAT_EPSILON FLT_EPSILON
|
112
|
+
#else
|
113
|
+
#define MRB_FLOAT_EPSILON DBL_EPSILON
|
114
|
+
#endif
|
115
|
+
#endif
|
116
|
+
|
117
|
+
/**
|
118
|
+
* MRuby C API entry point
|
119
|
+
*/
|
120
|
+
MRB_BEGIN_DECL
|
121
|
+
|
122
|
+
typedef uint8_t mrb_code;
|
123
|
+
|
124
|
+
/**
|
125
|
+
* \class mrb_aspec
|
126
|
+
*
|
127
|
+
* Specifies the number of arguments a function takes
|
128
|
+
*
|
129
|
+
* Example: `MRB_ARGS_REQ(2) | MRB_ARGS_OPT(1)` for a method that expects 2..3 arguments
|
130
|
+
*/
|
131
|
+
typedef uint32_t mrb_aspec;
|
132
|
+
|
133
|
+
struct mrb_irep;
|
134
|
+
struct mrb_state;
|
135
|
+
|
136
|
+
/**
|
137
|
+
* Function pointer type of custom allocator used in @see mrb_open_allocf.
|
138
|
+
*
|
139
|
+
* The function pointing it must behave similarly as realloc except:
|
140
|
+
* - If ptr is NULL it must allocate new space.
|
141
|
+
* - If s is NULL, ptr must be freed.
|
142
|
+
*
|
143
|
+
* See @see mrb_default_allocf for the default implementation.
|
144
|
+
*/
|
145
|
+
typedef void* (*mrb_allocf) (struct mrb_state *mrb, void*, size_t, void *ud);
|
146
|
+
|
147
|
+
#ifndef MRB_FIXED_STATE_ATEXIT_STACK_SIZE
|
148
|
+
#define MRB_FIXED_STATE_ATEXIT_STACK_SIZE 5
|
149
|
+
#endif
|
150
|
+
|
151
|
+
typedef struct {
|
152
|
+
mrb_sym mid;
|
153
|
+
int16_t argc;
|
154
|
+
int16_t acc;
|
155
|
+
const struct RProc *proc;
|
156
|
+
mrb_value *stack;
|
157
|
+
const mrb_code *pc; /* current address on iseq of this proc */
|
158
|
+
union {
|
159
|
+
struct REnv *env;
|
160
|
+
struct RClass *target_class;
|
161
|
+
} u;
|
162
|
+
} mrb_callinfo;
|
163
|
+
|
164
|
+
enum mrb_fiber_state {
|
165
|
+
MRB_FIBER_CREATED = 0,
|
166
|
+
MRB_FIBER_RUNNING,
|
167
|
+
MRB_FIBER_RESUMED,
|
168
|
+
MRB_FIBER_SUSPENDED,
|
169
|
+
MRB_FIBER_TRANSFERRED,
|
170
|
+
MRB_FIBER_TERMINATED,
|
171
|
+
};
|
172
|
+
|
173
|
+
struct mrb_context {
|
174
|
+
struct mrb_context *prev;
|
175
|
+
|
176
|
+
mrb_value *stbase, *stend; /* stack of virtual machine */
|
177
|
+
|
178
|
+
mrb_callinfo *ci;
|
179
|
+
mrb_callinfo *cibase, *ciend;
|
180
|
+
|
181
|
+
enum mrb_fiber_state status : 4;
|
182
|
+
mrb_bool vmexec : 1;
|
183
|
+
struct RFiber *fib;
|
184
|
+
};
|
185
|
+
|
186
|
+
#ifdef MRB_METHOD_CACHE_SIZE
|
187
|
+
# undef MRB_NO_METHOD_CACHE
|
188
|
+
#else
|
189
|
+
/* default method cache size: 256 */
|
190
|
+
/* cache size needs to be power of 2 */
|
191
|
+
# define MRB_METHOD_CACHE_SIZE (1<<8)
|
192
|
+
#endif
|
193
|
+
|
194
|
+
/**
|
195
|
+
* Function pointer type for a function callable by mruby.
|
196
|
+
*
|
197
|
+
* The arguments to the function are stored on the mrb_state. To get them see mrb_get_args
|
198
|
+
*
|
199
|
+
* @param mrb The mruby state
|
200
|
+
* @param self The self object
|
201
|
+
* @return [mrb_value] The function's return value
|
202
|
+
*/
|
203
|
+
typedef mrb_value (*mrb_func_t)(struct mrb_state *mrb, mrb_value self);
|
204
|
+
|
205
|
+
#ifndef MRB_USE_METHOD_T_STRUCT
|
206
|
+
typedef uintptr_t mrb_method_t;
|
207
|
+
#else
|
208
|
+
typedef struct {
|
209
|
+
uint8_t flags;
|
210
|
+
union {
|
211
|
+
struct RProc *proc;
|
212
|
+
mrb_func_t func;
|
213
|
+
};
|
214
|
+
} mrb_method_t;
|
215
|
+
#endif
|
216
|
+
|
217
|
+
#ifndef MRB_NO_METHOD_CACHE
|
218
|
+
struct mrb_cache_entry {
|
219
|
+
struct RClass *c, *c0;
|
220
|
+
mrb_sym mid;
|
221
|
+
mrb_method_t m;
|
222
|
+
};
|
223
|
+
#endif
|
224
|
+
|
225
|
+
struct mrb_jmpbuf;
|
226
|
+
|
227
|
+
typedef void (*mrb_atexit_func)(struct mrb_state*);
|
228
|
+
|
229
|
+
typedef struct mrb_state {
|
230
|
+
struct mrb_jmpbuf *jmp;
|
231
|
+
|
232
|
+
mrb_allocf allocf; /* memory allocation function */
|
233
|
+
void *allocf_ud; /* auxiliary data of allocf */
|
234
|
+
|
235
|
+
struct mrb_context *c;
|
236
|
+
struct mrb_context *root_c;
|
237
|
+
struct iv_tbl *globals; /* global variable table */
|
238
|
+
|
239
|
+
struct RObject *exc; /* exception */
|
240
|
+
|
241
|
+
struct RObject *top_self;
|
242
|
+
struct RClass *object_class; /* Object class */
|
243
|
+
struct RClass *class_class;
|
244
|
+
struct RClass *module_class;
|
245
|
+
struct RClass *proc_class;
|
246
|
+
struct RClass *string_class;
|
247
|
+
struct RClass *array_class;
|
248
|
+
struct RClass *hash_class;
|
249
|
+
struct RClass *range_class;
|
250
|
+
|
251
|
+
#ifndef MRB_NO_FLOAT
|
252
|
+
struct RClass *float_class;
|
253
|
+
#endif
|
254
|
+
struct RClass *integer_class;
|
255
|
+
struct RClass *true_class;
|
256
|
+
struct RClass *false_class;
|
257
|
+
struct RClass *nil_class;
|
258
|
+
struct RClass *symbol_class;
|
259
|
+
struct RClass *kernel_module;
|
260
|
+
|
261
|
+
mrb_gc gc;
|
262
|
+
|
263
|
+
#ifndef MRB_NO_METHOD_CACHE
|
264
|
+
struct mrb_cache_entry cache[MRB_METHOD_CACHE_SIZE];
|
265
|
+
#endif
|
266
|
+
|
267
|
+
mrb_sym symidx;
|
268
|
+
struct symbol_name *symtbl; /* symbol table */
|
269
|
+
mrb_sym symhash[256];
|
270
|
+
size_t symcapa;
|
271
|
+
#ifndef MRB_USE_ALL_SYMBOLS
|
272
|
+
char symbuf[8]; /* buffer for small symbol names */
|
273
|
+
#endif
|
274
|
+
|
275
|
+
#ifdef MRB_USE_DEBUG_HOOK
|
276
|
+
void (*code_fetch_hook)(struct mrb_state* mrb, const struct mrb_irep *irep, const mrb_code *pc, mrb_value *regs);
|
277
|
+
void (*debug_op_hook)(struct mrb_state* mrb, const struct mrb_irep *irep, const mrb_code *pc, mrb_value *regs);
|
278
|
+
#endif
|
279
|
+
|
280
|
+
#ifdef MRB_BYTECODE_DECODE_OPTION
|
281
|
+
mrb_code (*bytecode_decoder)(struct mrb_state* mrb, mrb_code code);
|
282
|
+
#endif
|
283
|
+
|
284
|
+
struct RClass *eException_class;
|
285
|
+
struct RClass *eStandardError_class;
|
286
|
+
struct RObject *nomem_err; /* pre-allocated NoMemoryError */
|
287
|
+
struct RObject *stack_err; /* pre-allocated SysStackError */
|
288
|
+
#ifdef MRB_GC_FIXED_ARENA
|
289
|
+
struct RObject *arena_err; /* pre-allocated arena overflow error */
|
290
|
+
#endif
|
291
|
+
|
292
|
+
void *ud; /* auxiliary data */
|
293
|
+
|
294
|
+
#ifdef MRB_FIXED_STATE_ATEXIT_STACK
|
295
|
+
mrb_atexit_func atexit_stack[MRB_FIXED_STATE_ATEXIT_STACK_SIZE];
|
296
|
+
#else
|
297
|
+
mrb_atexit_func *atexit_stack;
|
298
|
+
#endif
|
299
|
+
uint16_t atexit_stack_len;
|
300
|
+
} mrb_state;
|
301
|
+
|
302
|
+
/**
|
303
|
+
* Defines a new class.
|
304
|
+
*
|
305
|
+
* If you're creating a gem it may look something like this:
|
306
|
+
*
|
307
|
+
* !!!c
|
308
|
+
* void mrb_example_gem_init(mrb_state* mrb) {
|
309
|
+
* struct RClass *example_class;
|
310
|
+
* example_class = mrb_define_class(mrb, "Example_Class", mrb->object_class);
|
311
|
+
* }
|
312
|
+
*
|
313
|
+
* void mrb_example_gem_final(mrb_state* mrb) {
|
314
|
+
* //free(TheAnimals);
|
315
|
+
* }
|
316
|
+
*
|
317
|
+
* @param mrb The current mruby state.
|
318
|
+
* @param name The name of the defined class.
|
319
|
+
* @param super The new class parent.
|
320
|
+
* @return [struct RClass *] Reference to the newly defined class.
|
321
|
+
* @see mrb_define_class_under
|
322
|
+
*/
|
323
|
+
MRB_API struct RClass *mrb_define_class(mrb_state *mrb, const char *name, struct RClass *super);
|
324
|
+
MRB_API struct RClass *mrb_define_class_id(mrb_state *mrb, mrb_sym name, struct RClass *super);
|
325
|
+
|
326
|
+
/**
|
327
|
+
* Defines a new module.
|
328
|
+
*
|
329
|
+
* @param mrb The current mruby state.
|
330
|
+
* @param name The name of the module.
|
331
|
+
* @return [struct RClass *] Reference to the newly defined module.
|
332
|
+
*/
|
333
|
+
MRB_API struct RClass *mrb_define_module(mrb_state *mrb, const char *name);
|
334
|
+
MRB_API struct RClass *mrb_define_module_id(mrb_state *mrb, mrb_sym name);
|
335
|
+
|
336
|
+
MRB_API mrb_value mrb_singleton_class(mrb_state *mrb, mrb_value val);
|
337
|
+
MRB_API struct RClass *mrb_singleton_class_ptr(mrb_state *mrb, mrb_value val);
|
338
|
+
|
339
|
+
/**
|
340
|
+
* Include a module in another class or module.
|
341
|
+
* Equivalent to:
|
342
|
+
*
|
343
|
+
* module B
|
344
|
+
* include A
|
345
|
+
* end
|
346
|
+
* @param mrb The current mruby state.
|
347
|
+
* @param cla A reference to module or a class.
|
348
|
+
* @param included A reference to the module to be included.
|
349
|
+
*/
|
350
|
+
MRB_API void mrb_include_module(mrb_state *mrb, struct RClass *cla, struct RClass *included);
|
351
|
+
|
352
|
+
/**
|
353
|
+
* Prepends a module in another class or module.
|
354
|
+
*
|
355
|
+
* Equivalent to:
|
356
|
+
* module B
|
357
|
+
* prepend A
|
358
|
+
* end
|
359
|
+
* @param mrb The current mruby state.
|
360
|
+
* @param cla A reference to module or a class.
|
361
|
+
* @param prepended A reference to the module to be prepended.
|
362
|
+
*/
|
363
|
+
MRB_API void mrb_prepend_module(mrb_state *mrb, struct RClass *cla, struct RClass *prepended);
|
364
|
+
|
365
|
+
/**
|
366
|
+
* Defines a global function in ruby.
|
367
|
+
*
|
368
|
+
* If you're creating a gem it may look something like this
|
369
|
+
*
|
370
|
+
* Example:
|
371
|
+
*
|
372
|
+
* mrb_value example_method(mrb_state* mrb, mrb_value self)
|
373
|
+
* {
|
374
|
+
* puts("Executing example command!");
|
375
|
+
* return self;
|
376
|
+
* }
|
377
|
+
*
|
378
|
+
* void mrb_example_gem_init(mrb_state* mrb)
|
379
|
+
* {
|
380
|
+
* mrb_define_method(mrb, mrb->kernel_module, "example_method", example_method, MRB_ARGS_NONE());
|
381
|
+
* }
|
382
|
+
*
|
383
|
+
* @param mrb The MRuby state reference.
|
384
|
+
* @param cla The class pointer where the method will be defined.
|
385
|
+
* @param name The name of the method being defined.
|
386
|
+
* @param func The function pointer to the method definition.
|
387
|
+
* @param aspec The method parameters declaration.
|
388
|
+
*/
|
389
|
+
MRB_API void mrb_define_method(mrb_state *mrb, struct RClass *cla, const char *name, mrb_func_t func, mrb_aspec aspec);
|
390
|
+
MRB_API void mrb_define_method_id(mrb_state *mrb, struct RClass *c, mrb_sym mid, mrb_func_t func, mrb_aspec aspec);
|
391
|
+
|
392
|
+
/**
|
393
|
+
* Defines a class method.
|
394
|
+
*
|
395
|
+
* Example:
|
396
|
+
*
|
397
|
+
* # Ruby style
|
398
|
+
* class Foo
|
399
|
+
* def Foo.bar
|
400
|
+
* end
|
401
|
+
* end
|
402
|
+
* // C style
|
403
|
+
* mrb_value bar_method(mrb_state* mrb, mrb_value self){
|
404
|
+
* return mrb_nil_value();
|
405
|
+
* }
|
406
|
+
* void mrb_example_gem_init(mrb_state* mrb){
|
407
|
+
* struct RClass *foo;
|
408
|
+
* foo = mrb_define_class(mrb, "Foo", mrb->object_class);
|
409
|
+
* mrb_define_class_method(mrb, foo, "bar", bar_method, MRB_ARGS_NONE());
|
410
|
+
* }
|
411
|
+
* @param mrb The MRuby state reference.
|
412
|
+
* @param cla The class where the class method will be defined.
|
413
|
+
* @param name The name of the class method being defined.
|
414
|
+
* @param fun The function pointer to the class method definition.
|
415
|
+
* @param aspec The method parameters declaration.
|
416
|
+
*/
|
417
|
+
MRB_API void mrb_define_class_method(mrb_state *mrb, struct RClass *cla, const char *name, mrb_func_t fun, mrb_aspec aspec);
|
418
|
+
MRB_API void mrb_define_class_method_id(mrb_state *mrb, struct RClass *cla, mrb_sym name, mrb_func_t fun, mrb_aspec aspec);
|
419
|
+
|
420
|
+
/**
|
421
|
+
* Defines a singleton method
|
422
|
+
*
|
423
|
+
* @see mrb_define_class_method
|
424
|
+
*/
|
425
|
+
MRB_API void mrb_define_singleton_method(mrb_state *mrb, struct RObject *cla, const char *name, mrb_func_t fun, mrb_aspec aspec);
|
426
|
+
MRB_API void mrb_define_singleton_method_id(mrb_state *mrb, struct RObject *cla, mrb_sym name, mrb_func_t fun, mrb_aspec aspec);
|
427
|
+
|
428
|
+
/**
|
429
|
+
* Defines a module function.
|
430
|
+
*
|
431
|
+
* Example:
|
432
|
+
*
|
433
|
+
* # Ruby style
|
434
|
+
* module Foo
|
435
|
+
* def Foo.bar
|
436
|
+
* end
|
437
|
+
* end
|
438
|
+
* // C style
|
439
|
+
* mrb_value bar_method(mrb_state* mrb, mrb_value self){
|
440
|
+
* return mrb_nil_value();
|
441
|
+
* }
|
442
|
+
* void mrb_example_gem_init(mrb_state* mrb){
|
443
|
+
* struct RClass *foo;
|
444
|
+
* foo = mrb_define_module(mrb, "Foo");
|
445
|
+
* mrb_define_module_function(mrb, foo, "bar", bar_method, MRB_ARGS_NONE());
|
446
|
+
* }
|
447
|
+
* @param mrb The MRuby state reference.
|
448
|
+
* @param cla The module where the module function will be defined.
|
449
|
+
* @param name The name of the module function being defined.
|
450
|
+
* @param fun The function pointer to the module function definition.
|
451
|
+
* @param aspec The method parameters declaration.
|
452
|
+
*/
|
453
|
+
MRB_API void mrb_define_module_function(mrb_state *mrb, struct RClass *cla, const char *name, mrb_func_t fun, mrb_aspec aspec);
|
454
|
+
MRB_API void mrb_define_module_function_id(mrb_state *mrb, struct RClass *cla, mrb_sym name, mrb_func_t fun, mrb_aspec aspec);
|
455
|
+
|
456
|
+
/**
|
457
|
+
* Defines a constant.
|
458
|
+
*
|
459
|
+
* Example:
|
460
|
+
*
|
461
|
+
* # Ruby style
|
462
|
+
* class ExampleClass
|
463
|
+
* AGE = 22
|
464
|
+
* end
|
465
|
+
* // C style
|
466
|
+
* #include <stdio.h>
|
467
|
+
* #include <mruby.h>
|
468
|
+
*
|
469
|
+
* void
|
470
|
+
* mrb_example_gem_init(mrb_state* mrb){
|
471
|
+
* mrb_define_const(mrb, mrb->kernel_module, "AGE", mrb_fixnum_value(22));
|
472
|
+
* }
|
473
|
+
*
|
474
|
+
* mrb_value
|
475
|
+
* mrb_example_gem_final(mrb_state* mrb){
|
476
|
+
* }
|
477
|
+
* @param mrb The MRuby state reference.
|
478
|
+
* @param cla A class or module the constant is defined in.
|
479
|
+
* @param name The name of the constant being defined.
|
480
|
+
* @param val The value for the constant.
|
481
|
+
*/
|
482
|
+
MRB_API void mrb_define_const(mrb_state* mrb, struct RClass* cla, const char *name, mrb_value val);
|
483
|
+
MRB_API void mrb_define_const_id(mrb_state* mrb, struct RClass* cla, mrb_sym name, mrb_value val);
|
484
|
+
|
485
|
+
/**
|
486
|
+
* Undefines a method.
|
487
|
+
*
|
488
|
+
* Example:
|
489
|
+
*
|
490
|
+
* # Ruby style
|
491
|
+
*
|
492
|
+
* class ExampleClassA
|
493
|
+
* def example_method
|
494
|
+
* "example"
|
495
|
+
* end
|
496
|
+
* end
|
497
|
+
* ExampleClassA.new.example_method # => example
|
498
|
+
*
|
499
|
+
* class ExampleClassB < ExampleClassA
|
500
|
+
* undef_method :example_method
|
501
|
+
* end
|
502
|
+
*
|
503
|
+
* ExampleClassB.new.example_method # => undefined method 'example_method' for ExampleClassB (NoMethodError)
|
504
|
+
*
|
505
|
+
* // C style
|
506
|
+
* #include <stdio.h>
|
507
|
+
* #include <mruby.h>
|
508
|
+
*
|
509
|
+
* mrb_value
|
510
|
+
* mrb_example_method(mrb_state *mrb){
|
511
|
+
* return mrb_str_new_lit(mrb, "example");
|
512
|
+
* }
|
513
|
+
*
|
514
|
+
* void
|
515
|
+
* mrb_example_gem_init(mrb_state* mrb){
|
516
|
+
* struct RClass *example_class_a;
|
517
|
+
* struct RClass *example_class_b;
|
518
|
+
* struct RClass *example_class_c;
|
519
|
+
*
|
520
|
+
* example_class_a = mrb_define_class(mrb, "ExampleClassA", mrb->object_class);
|
521
|
+
* mrb_define_method(mrb, example_class_a, "example_method", mrb_example_method, MRB_ARGS_NONE());
|
522
|
+
* example_class_b = mrb_define_class(mrb, "ExampleClassB", example_class_a);
|
523
|
+
* example_class_c = mrb_define_class(mrb, "ExampleClassC", example_class_b);
|
524
|
+
* mrb_undef_method(mrb, example_class_c, "example_method");
|
525
|
+
* }
|
526
|
+
*
|
527
|
+
* mrb_example_gem_final(mrb_state* mrb){
|
528
|
+
* }
|
529
|
+
* @param mrb The mruby state reference.
|
530
|
+
* @param cla The class the method will be undefined from.
|
531
|
+
* @param name The name of the method to be undefined.
|
532
|
+
*/
|
533
|
+
MRB_API void mrb_undef_method(mrb_state *mrb, struct RClass *cla, const char *name);
|
534
|
+
MRB_API void mrb_undef_method_id(mrb_state*, struct RClass*, mrb_sym);
|
535
|
+
|
536
|
+
/**
|
537
|
+
* Undefine a class method.
|
538
|
+
* Example:
|
539
|
+
*
|
540
|
+
* # Ruby style
|
541
|
+
* class ExampleClass
|
542
|
+
* def self.example_method
|
543
|
+
* "example"
|
544
|
+
* end
|
545
|
+
* end
|
546
|
+
*
|
547
|
+
* ExampleClass.example_method
|
548
|
+
*
|
549
|
+
* // C style
|
550
|
+
* #include <stdio.h>
|
551
|
+
* #include <mruby.h>
|
552
|
+
*
|
553
|
+
* mrb_value
|
554
|
+
* mrb_example_method(mrb_state *mrb){
|
555
|
+
* return mrb_str_new_lit(mrb, "example");
|
556
|
+
* }
|
557
|
+
*
|
558
|
+
* void
|
559
|
+
* mrb_example_gem_init(mrb_state* mrb){
|
560
|
+
* struct RClass *example_class;
|
561
|
+
* example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class);
|
562
|
+
* mrb_define_class_method(mrb, example_class, "example_method", mrb_example_method, MRB_ARGS_NONE());
|
563
|
+
* mrb_undef_class_method(mrb, example_class, "example_method");
|
564
|
+
* }
|
565
|
+
*
|
566
|
+
* void
|
567
|
+
* mrb_example_gem_final(mrb_state* mrb){
|
568
|
+
* }
|
569
|
+
* @param mrb The mruby state reference.
|
570
|
+
* @param cls A class the class method will be undefined from.
|
571
|
+
* @param name The name of the class method to be undefined.
|
572
|
+
*/
|
573
|
+
MRB_API void mrb_undef_class_method(mrb_state *mrb, struct RClass *cls, const char *name);
|
574
|
+
MRB_API void mrb_undef_class_method_id(mrb_state *mrb, struct RClass *cls, mrb_sym name);
|
575
|
+
|
576
|
+
/**
|
577
|
+
* Initialize a new object instance of c class.
|
578
|
+
*
|
579
|
+
* Example:
|
580
|
+
*
|
581
|
+
* # Ruby style
|
582
|
+
* class ExampleClass
|
583
|
+
* end
|
584
|
+
*
|
585
|
+
* p ExampleClass # => #<ExampleClass:0x9958588>
|
586
|
+
* // C style
|
587
|
+
* #include <stdio.h>
|
588
|
+
* #include <mruby.h>
|
589
|
+
*
|
590
|
+
* void
|
591
|
+
* mrb_example_gem_init(mrb_state* mrb) {
|
592
|
+
* struct RClass *example_class;
|
593
|
+
* mrb_value obj;
|
594
|
+
* example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class); # => class ExampleClass; end
|
595
|
+
* obj = mrb_obj_new(mrb, example_class, 0, NULL); # => ExampleClass.new
|
596
|
+
* mrb_p(mrb, obj); // => Kernel#p
|
597
|
+
* }
|
598
|
+
* @param mrb The current mruby state.
|
599
|
+
* @param c Reference to the class of the new object.
|
600
|
+
* @param argc Number of arguments in argv
|
601
|
+
* @param argv Array of mrb_value to initialize the object
|
602
|
+
* @return [mrb_value] The newly initialized object
|
603
|
+
*/
|
604
|
+
MRB_API mrb_value mrb_obj_new(mrb_state *mrb, struct RClass *c, mrb_int argc, const mrb_value *argv);
|
605
|
+
|
606
|
+
/** @see mrb_obj_new */
|
607
|
+
MRB_INLINE mrb_value mrb_class_new_instance(mrb_state *mrb, mrb_int argc, const mrb_value *argv, struct RClass *c)
|
608
|
+
{
|
609
|
+
return mrb_obj_new(mrb,c,argc,argv);
|
610
|
+
}
|
611
|
+
|
612
|
+
/**
|
613
|
+
* Creates a new instance of Class, Class.
|
614
|
+
*
|
615
|
+
* Example:
|
616
|
+
*
|
617
|
+
* void
|
618
|
+
* mrb_example_gem_init(mrb_state* mrb) {
|
619
|
+
* struct RClass *example_class;
|
620
|
+
*
|
621
|
+
* mrb_value obj;
|
622
|
+
* example_class = mrb_class_new(mrb, mrb->object_class);
|
623
|
+
* obj = mrb_obj_new(mrb, example_class, 0, NULL); // => #<#<Class:0x9a945b8>:0x9a94588>
|
624
|
+
* mrb_p(mrb, obj); // => Kernel#p
|
625
|
+
* }
|
626
|
+
*
|
627
|
+
* @param mrb The current mruby state.
|
628
|
+
* @param super The super class or parent.
|
629
|
+
* @return [struct RClass *] Reference to the new class.
|
630
|
+
*/
|
631
|
+
MRB_API struct RClass * mrb_class_new(mrb_state *mrb, struct RClass *super);
|
632
|
+
|
633
|
+
/**
|
634
|
+
* Creates a new module, Module.
|
635
|
+
*
|
636
|
+
* Example:
|
637
|
+
* void
|
638
|
+
* mrb_example_gem_init(mrb_state* mrb) {
|
639
|
+
* struct RClass *example_module;
|
640
|
+
*
|
641
|
+
* example_module = mrb_module_new(mrb);
|
642
|
+
* }
|
643
|
+
*
|
644
|
+
* @param mrb The current mruby state.
|
645
|
+
* @return [struct RClass *] Reference to the new module.
|
646
|
+
*/
|
647
|
+
MRB_API struct RClass * mrb_module_new(mrb_state *mrb);
|
648
|
+
|
649
|
+
/**
|
650
|
+
* Returns an mrb_bool. True if class was defined, and false if the class was not defined.
|
651
|
+
*
|
652
|
+
* Example:
|
653
|
+
* void
|
654
|
+
* mrb_example_gem_init(mrb_state* mrb) {
|
655
|
+
* struct RClass *example_class;
|
656
|
+
* mrb_bool cd;
|
657
|
+
*
|
658
|
+
* example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class);
|
659
|
+
* cd = mrb_class_defined(mrb, "ExampleClass");
|
660
|
+
*
|
661
|
+
* // If mrb_class_defined returns 1 then puts "True"
|
662
|
+
* // If mrb_class_defined returns 0 then puts "False"
|
663
|
+
* if (cd == 1){
|
664
|
+
* puts("True");
|
665
|
+
* }
|
666
|
+
* else {
|
667
|
+
* puts("False");
|
668
|
+
* }
|
669
|
+
* }
|
670
|
+
*
|
671
|
+
* @param mrb The current mruby state.
|
672
|
+
* @param name A string representing the name of the class.
|
673
|
+
* @return [mrb_bool] A boolean value.
|
674
|
+
*/
|
675
|
+
MRB_API mrb_bool mrb_class_defined(mrb_state *mrb, const char *name);
|
676
|
+
MRB_API mrb_bool mrb_class_defined_id(mrb_state *mrb, mrb_sym name);
|
677
|
+
|
678
|
+
/**
|
679
|
+
* Gets a class.
|
680
|
+
* @param mrb The current mruby state.
|
681
|
+
* @param name The name of the class.
|
682
|
+
* @return [struct RClass *] A reference to the class.
|
683
|
+
*/
|
684
|
+
MRB_API struct RClass* mrb_class_get(mrb_state *mrb, const char *name);
|
685
|
+
MRB_API struct RClass* mrb_class_get_id(mrb_state *mrb, mrb_sym name);
|
686
|
+
|
687
|
+
/**
|
688
|
+
* Gets a exception class.
|
689
|
+
* @param mrb The current mruby state.
|
690
|
+
* @param name The name of the class.
|
691
|
+
* @return [struct RClass *] A reference to the class.
|
692
|
+
*/
|
693
|
+
MRB_API struct RClass* mrb_exc_get_id(mrb_state *mrb, mrb_sym name);
|
694
|
+
#define mrb_exc_get(mrb, name) mrb_exc_get_id(mrb, mrb_intern_cstr(mrb, name))
|
695
|
+
|
696
|
+
/**
|
697
|
+
* Returns an mrb_bool. True if inner class was defined, and false if the inner class was not defined.
|
698
|
+
*
|
699
|
+
* Example:
|
700
|
+
* void
|
701
|
+
* mrb_example_gem_init(mrb_state* mrb) {
|
702
|
+
* struct RClass *example_outer, *example_inner;
|
703
|
+
* mrb_bool cd;
|
704
|
+
*
|
705
|
+
* example_outer = mrb_define_module(mrb, "ExampleOuter");
|
706
|
+
*
|
707
|
+
* example_inner = mrb_define_class_under(mrb, example_outer, "ExampleInner", mrb->object_class);
|
708
|
+
* cd = mrb_class_defined_under(mrb, example_outer, "ExampleInner");
|
709
|
+
*
|
710
|
+
* // If mrb_class_defined_under returns 1 then puts "True"
|
711
|
+
* // If mrb_class_defined_under returns 0 then puts "False"
|
712
|
+
* if (cd == 1){
|
713
|
+
* puts("True");
|
714
|
+
* }
|
715
|
+
* else {
|
716
|
+
* puts("False");
|
717
|
+
* }
|
718
|
+
* }
|
719
|
+
*
|
720
|
+
* @param mrb The current mruby state.
|
721
|
+
* @param outer The name of the outer class.
|
722
|
+
* @param name A string representing the name of the inner class.
|
723
|
+
* @return [mrb_bool] A boolean value.
|
724
|
+
*/
|
725
|
+
MRB_API mrb_bool mrb_class_defined_under(mrb_state *mrb, struct RClass *outer, const char *name);
|
726
|
+
MRB_API mrb_bool mrb_class_defined_under_id(mrb_state *mrb, struct RClass *outer, mrb_sym name);
|
727
|
+
|
728
|
+
/**
|
729
|
+
* Gets a child class.
|
730
|
+
* @param mrb The current mruby state.
|
731
|
+
* @param outer The name of the parent class.
|
732
|
+
* @param name The name of the class.
|
733
|
+
* @return [struct RClass *] A reference to the class.
|
734
|
+
*/
|
735
|
+
MRB_API struct RClass * mrb_class_get_under(mrb_state *mrb, struct RClass *outer, const char *name);
|
736
|
+
MRB_API struct RClass * mrb_class_get_under_id(mrb_state *mrb, struct RClass *outer, mrb_sym name);
|
737
|
+
|
738
|
+
/**
|
739
|
+
* Gets a module.
|
740
|
+
* @param mrb The current mruby state.
|
741
|
+
* @param name The name of the module.
|
742
|
+
* @return [struct RClass *] A reference to the module.
|
743
|
+
*/
|
744
|
+
MRB_API struct RClass * mrb_module_get(mrb_state *mrb, const char *name);
|
745
|
+
MRB_API struct RClass * mrb_module_get_id(mrb_state *mrb, mrb_sym name);
|
746
|
+
|
747
|
+
/**
|
748
|
+
* Gets a module defined under another module.
|
749
|
+
* @param mrb The current mruby state.
|
750
|
+
* @param outer The name of the outer module.
|
751
|
+
* @param name The name of the module.
|
752
|
+
* @return [struct RClass *] A reference to the module.
|
753
|
+
*/
|
754
|
+
MRB_API struct RClass * mrb_module_get_under(mrb_state *mrb, struct RClass *outer, const char *name);
|
755
|
+
MRB_API struct RClass * mrb_module_get_under_id(mrb_state *mrb, struct RClass *outer, mrb_sym name);
|
756
|
+
|
757
|
+
/* a function to raise NotImplementedError with current method name */
|
758
|
+
MRB_API void mrb_notimplement(mrb_state*);
|
759
|
+
/* a function to be replacement of unimplemented method */
|
760
|
+
MRB_API mrb_value mrb_notimplement_m(mrb_state*, mrb_value);
|
761
|
+
|
762
|
+
/**
|
763
|
+
* Duplicate an object.
|
764
|
+
*
|
765
|
+
* Equivalent to:
|
766
|
+
* Object#dup
|
767
|
+
* @param mrb The current mruby state.
|
768
|
+
* @param obj Object to be duplicate.
|
769
|
+
* @return [mrb_value] The newly duplicated object.
|
770
|
+
*/
|
771
|
+
MRB_API mrb_value mrb_obj_dup(mrb_state *mrb, mrb_value obj);
|
772
|
+
|
773
|
+
/**
|
774
|
+
* Returns true if obj responds to the given method. If the method was defined for that
|
775
|
+
* class it returns true, it returns false otherwise.
|
776
|
+
*
|
777
|
+
* Example:
|
778
|
+
* # Ruby style
|
779
|
+
* class ExampleClass
|
780
|
+
* def example_method
|
781
|
+
* end
|
782
|
+
* end
|
783
|
+
*
|
784
|
+
* ExampleClass.new.respond_to?(:example_method) # => true
|
785
|
+
*
|
786
|
+
* // C style
|
787
|
+
* void
|
788
|
+
* mrb_example_gem_init(mrb_state* mrb) {
|
789
|
+
* struct RClass *example_class;
|
790
|
+
* mrb_sym mid;
|
791
|
+
* mrb_bool obj_resp;
|
792
|
+
*
|
793
|
+
* example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class);
|
794
|
+
* mrb_define_method(mrb, example_class, "example_method", exampleMethod, MRB_ARGS_NONE());
|
795
|
+
* mid = mrb_intern_str(mrb, mrb_str_new_lit(mrb, "example_method" ));
|
796
|
+
* obj_resp = mrb_obj_respond_to(mrb, example_class, mid); // => 1(true in Ruby world)
|
797
|
+
*
|
798
|
+
* // If mrb_obj_respond_to returns 1 then puts "True"
|
799
|
+
* // If mrb_obj_respond_to returns 0 then puts "False"
|
800
|
+
* if (obj_resp == 1) {
|
801
|
+
* puts("True");
|
802
|
+
* }
|
803
|
+
* else if (obj_resp == 0) {
|
804
|
+
* puts("False");
|
805
|
+
* }
|
806
|
+
* }
|
807
|
+
*
|
808
|
+
* @param mrb The current mruby state.
|
809
|
+
* @param c A reference to a class.
|
810
|
+
* @param mid A symbol referencing a method id.
|
811
|
+
* @return [mrb_bool] A boolean value.
|
812
|
+
*/
|
813
|
+
MRB_API mrb_bool mrb_obj_respond_to(mrb_state *mrb, struct RClass* c, mrb_sym mid);
|
814
|
+
|
815
|
+
/**
|
816
|
+
* Defines a new class under a given module
|
817
|
+
*
|
818
|
+
* @param mrb The current mruby state.
|
819
|
+
* @param outer Reference to the module under which the new class will be defined
|
820
|
+
* @param name The name of the defined class
|
821
|
+
* @param super The new class parent
|
822
|
+
* @return [struct RClass *] Reference to the newly defined class
|
823
|
+
* @see mrb_define_class
|
824
|
+
*/
|
825
|
+
MRB_API struct RClass* mrb_define_class_under(mrb_state *mrb, struct RClass *outer, const char *name, struct RClass *super);
|
826
|
+
MRB_API struct RClass* mrb_define_class_under_id(mrb_state *mrb, struct RClass *outer, mrb_sym name, struct RClass *super);
|
827
|
+
|
828
|
+
MRB_API struct RClass* mrb_define_module_under(mrb_state *mrb, struct RClass *outer, const char *name);
|
829
|
+
MRB_API struct RClass* mrb_define_module_under_id(mrb_state *mrb, struct RClass *outer, mrb_sym name);
|
830
|
+
|
831
|
+
/**
|
832
|
+
* Function requires n arguments.
|
833
|
+
*
|
834
|
+
* @param n
|
835
|
+
* The number of required arguments.
|
836
|
+
*/
|
837
|
+
#define MRB_ARGS_REQ(n) ((mrb_aspec)((n)&0x1f) << 18)
|
838
|
+
|
839
|
+
/**
|
840
|
+
* Function takes n optional arguments
|
841
|
+
*
|
842
|
+
* @param n
|
843
|
+
* The number of optional arguments.
|
844
|
+
*/
|
845
|
+
#define MRB_ARGS_OPT(n) ((mrb_aspec)((n)&0x1f) << 13)
|
846
|
+
|
847
|
+
/**
|
848
|
+
* Function takes n1 mandatory arguments and n2 optional arguments
|
849
|
+
*
|
850
|
+
* @param n1
|
851
|
+
* The number of required arguments.
|
852
|
+
* @param n2
|
853
|
+
* The number of optional arguments.
|
854
|
+
*/
|
855
|
+
#define MRB_ARGS_ARG(n1,n2) (MRB_ARGS_REQ(n1)|MRB_ARGS_OPT(n2))
|
856
|
+
|
857
|
+
/** rest argument */
|
858
|
+
#define MRB_ARGS_REST() ((mrb_aspec)(1 << 12))
|
859
|
+
|
860
|
+
/** required arguments after rest */
|
861
|
+
#define MRB_ARGS_POST(n) ((mrb_aspec)((n)&0x1f) << 7)
|
862
|
+
|
863
|
+
/** keyword arguments (n of keys, kdict) */
|
864
|
+
#define MRB_ARGS_KEY(n1,n2) ((mrb_aspec)((((n1)&0x1f) << 2) | ((n2)?(1<<1):0)))
|
865
|
+
|
866
|
+
/**
|
867
|
+
* Function takes a block argument
|
868
|
+
*/
|
869
|
+
#define MRB_ARGS_BLOCK() ((mrb_aspec)1)
|
870
|
+
|
871
|
+
/**
|
872
|
+
* Function accepts any number of arguments
|
873
|
+
*/
|
874
|
+
#define MRB_ARGS_ANY() MRB_ARGS_REST()
|
875
|
+
|
876
|
+
/**
|
877
|
+
* Function accepts no arguments
|
878
|
+
*/
|
879
|
+
#define MRB_ARGS_NONE() ((mrb_aspec)0)
|
880
|
+
|
881
|
+
/**
|
882
|
+
* Format specifiers for {mrb_get_args} function
|
883
|
+
*
|
884
|
+
* Must be a C string composed of the following format specifiers:
|
885
|
+
*
|
886
|
+
* | char | Ruby type | C types | Notes |
|
887
|
+
* |:----:|----------------|-------------------|----------------------------------------------------|
|
888
|
+
* | `o` | {Object} | {mrb_value} | Could be used to retrieve any type of argument |
|
889
|
+
* | `C` | {Class}/{Module} | {mrb_value} | |
|
890
|
+
* | `S` | {String} | {mrb_value} | when `!` follows, the value may be `nil` |
|
891
|
+
* | `A` | {Array} | {mrb_value} | when `!` follows, the value may be `nil` |
|
892
|
+
* | `H` | {Hash} | {mrb_value} | when `!` follows, the value may be `nil` |
|
893
|
+
* | `s` | {String} | const char *, {mrb_int} | Receive two arguments; `s!` gives (`NULL`,`0`) for `nil` |
|
894
|
+
* | `z` | {String} | const char * | `NULL` terminated string; `z!` gives `NULL` for `nil` |
|
895
|
+
* | `a` | {Array} | const {mrb_value} *, {mrb_int} | Receive two arguments; `a!` gives (`NULL`,`0`) for `nil` |
|
896
|
+
* | `f` | {Integer}/{Float} | {mrb_float} | |
|
897
|
+
* | `i` | {Integer}/{Float} | {mrb_int} | |
|
898
|
+
* | `b` | boolean | {mrb_bool} | |
|
899
|
+
* | `n` | {String}/{Symbol} | {mrb_sym} | |
|
900
|
+
* | `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 * | |
|
902
|
+
* | `&` | block | {mrb_value} | &! raises exception if no block given. |
|
903
|
+
* | `*` | rest arguments | const {mrb_value} *, {mrb_int} | Receive the rest of arguments as an array; `*!` avoid copy of the stack. |
|
904
|
+
* | <code>\|</code> | optional | | After this spec following specs would be optional. |
|
905
|
+
* | `?` | optional given | {mrb_bool} | `TRUE` if preceding argument is given. Used to check optional argument is given. |
|
906
|
+
* | `:` | keyword args | {mrb_kwargs} const | Get keyword arguments. @see mrb_kwargs |
|
907
|
+
*
|
908
|
+
* @see mrb_get_args
|
909
|
+
*/
|
910
|
+
typedef const char *mrb_args_format;
|
911
|
+
|
912
|
+
/**
|
913
|
+
* Get keyword arguments by `mrb_get_args()` with `:` specifier.
|
914
|
+
*
|
915
|
+
* `mrb_kwargs::num` indicates that the number of keyword values.
|
916
|
+
*
|
917
|
+
* `mrb_kwargs::values` is an object array, and the keyword argument corresponding to the string array is assigned.
|
918
|
+
* Note that `undef` is assigned if there is no keyword argument corresponding to `mrb_kwargs::optional`.
|
919
|
+
*
|
920
|
+
* `mrb_kwargs::table` accepts a string array.
|
921
|
+
*
|
922
|
+
* `mrb_kwargs::required` indicates that the specified number of keywords starting from the beginning of the string array are required.
|
923
|
+
*
|
924
|
+
* `mrb_kwargs::rest` is the remaining keyword argument that can be accepted as `**rest` in Ruby.
|
925
|
+
* If `NULL` is specified, `ArgumentError` is raised when there is an undefined keyword.
|
926
|
+
*
|
927
|
+
* Examples:
|
928
|
+
*
|
929
|
+
* // def method(a: 1, b: 2)
|
930
|
+
*
|
931
|
+
* uint32_t kw_num = 2;
|
932
|
+
* const char *kw_names[kw_num] = { "a", "b" };
|
933
|
+
* uint32_t kw_required = 0;
|
934
|
+
* mrb_value kw_values[kw_num];
|
935
|
+
* const mrb_kwargs kwargs = { kw_num, kw_required, kw_names, kw_values, NULL };
|
936
|
+
*
|
937
|
+
* mrb_get_args(mrb, ":", &kwargs);
|
938
|
+
* if (mrb_undef_p(kw_values[0])) { kw_values[0] = mrb_fixnum_value(1); }
|
939
|
+
* if (mrb_undef_p(kw_values[1])) { kw_values[1] = mrb_fixnum_value(2); }
|
940
|
+
*
|
941
|
+
*
|
942
|
+
* // def method(str, x:, y: 2, z: "default string", **opts)
|
943
|
+
*
|
944
|
+
* mrb_value str, kw_rest;
|
945
|
+
* uint32_t kw_num = 3;
|
946
|
+
* const mrb_sym kw_names[kw_num] = { MRB_SYM(x), MRB_SYM(y), MRB_SYM(z) };
|
947
|
+
* uint32_t kw_required = 1;
|
948
|
+
* mrb_value kw_values[kw_num];
|
949
|
+
* const mrb_kwargs kwargs = { kw_num, kw_required, kw_names, kw_values, &kw_rest };
|
950
|
+
*
|
951
|
+
* mrb_get_args(mrb, "S:", &str, &kwargs);
|
952
|
+
* // or: mrb_get_args(mrb, ":S", &kwargs, &str);
|
953
|
+
* if (mrb_undef_p(kw_values[1])) { kw_values[1] = mrb_fixnum_value(2); }
|
954
|
+
* if (mrb_undef_p(kw_values[2])) { kw_values[2] = mrb_str_new_cstr(mrb, "default string"); }
|
955
|
+
*/
|
956
|
+
typedef struct mrb_kwargs mrb_kwargs;
|
957
|
+
|
958
|
+
struct mrb_kwargs
|
959
|
+
{
|
960
|
+
uint32_t num; /* number of keyword arguments */
|
961
|
+
uint32_t required; /* number of required keyword arguments */
|
962
|
+
const mrb_sym *table; /* C array of symbols for keyword names */
|
963
|
+
mrb_value *values; /* keyword argument values */
|
964
|
+
mrb_value *rest; /* keyword rest (dict) */
|
965
|
+
};
|
966
|
+
|
967
|
+
/**
|
968
|
+
* Retrieve arguments from mrb_state.
|
969
|
+
*
|
970
|
+
* @param mrb The current MRuby state.
|
971
|
+
* @param format is a list of format specifiers
|
972
|
+
* @param ... The passing variadic arguments must be a pointer of retrieving type.
|
973
|
+
* @return the number of arguments retrieved.
|
974
|
+
* @see mrb_args_format
|
975
|
+
* @see mrb_kwargs
|
976
|
+
*/
|
977
|
+
MRB_API mrb_int mrb_get_args(mrb_state *mrb, mrb_args_format format, ...);
|
978
|
+
|
979
|
+
MRB_INLINE mrb_sym
|
980
|
+
mrb_get_mid(mrb_state *mrb) /* get method symbol */
|
981
|
+
{
|
982
|
+
return mrb->c->ci->mid;
|
983
|
+
}
|
984
|
+
|
985
|
+
/**
|
986
|
+
* Retrieve number of arguments from mrb_state.
|
987
|
+
*
|
988
|
+
* Correctly handles *splat arguments.
|
989
|
+
*/
|
990
|
+
MRB_API mrb_int mrb_get_argc(mrb_state *mrb);
|
991
|
+
|
992
|
+
/**
|
993
|
+
* Retrieve an array of arguments from mrb_state.
|
994
|
+
*
|
995
|
+
* Correctly handles *splat arguments.
|
996
|
+
*/
|
997
|
+
MRB_API const mrb_value *mrb_get_argv(mrb_state *mrb);
|
998
|
+
|
999
|
+
/**
|
1000
|
+
* Retrieve the first and only argument from mrb_state.
|
1001
|
+
* Raises ArgumentError unless the number of arguments is exactly one.
|
1002
|
+
*
|
1003
|
+
* Correctly handles *splat arguments.
|
1004
|
+
*/
|
1005
|
+
MRB_API mrb_value mrb_get_arg1(mrb_state *mrb);
|
1006
|
+
|
1007
|
+
/* `strlen` for character string literals (use with caution or `strlen` instead)
|
1008
|
+
Adjacent string literals are concatenated in C/C++ in translation phase 6.
|
1009
|
+
If `lit` is not one, the compiler will report a syntax error:
|
1010
|
+
MSVC: "error C2143: syntax error : missing ')' before 'string'"
|
1011
|
+
GCC: "error: expected ')' before string constant"
|
1012
|
+
*/
|
1013
|
+
#define mrb_strlen_lit(lit) (sizeof(lit "") - 1)
|
1014
|
+
|
1015
|
+
/**
|
1016
|
+
* Call existing ruby functions.
|
1017
|
+
*
|
1018
|
+
* Example:
|
1019
|
+
*
|
1020
|
+
* #include <stdio.h>
|
1021
|
+
* #include <mruby.h>
|
1022
|
+
* #include "mruby/compile.h"
|
1023
|
+
*
|
1024
|
+
* int
|
1025
|
+
* main()
|
1026
|
+
* {
|
1027
|
+
* mrb_int i = 99;
|
1028
|
+
* mrb_state *mrb = mrb_open();
|
1029
|
+
*
|
1030
|
+
* if (!mrb) { }
|
1031
|
+
* FILE *fp = fopen("test.rb","r");
|
1032
|
+
* mrb_value obj = mrb_load_file(mrb,fp);
|
1033
|
+
* mrb_funcall(mrb, obj, "method_name", 1, mrb_fixnum_value(i));
|
1034
|
+
* mrb_funcall_id(mrb, obj, MRB_SYM(method_name), 1, mrb_fixnum_value(i));
|
1035
|
+
* fclose(fp);
|
1036
|
+
* mrb_close(mrb);
|
1037
|
+
* }
|
1038
|
+
*
|
1039
|
+
* @param mrb The current mruby state.
|
1040
|
+
* @param val A reference to an mruby value.
|
1041
|
+
* @param name The name of the method.
|
1042
|
+
* @param argc The number of arguments the method has.
|
1043
|
+
* @param ... Variadic values(not type safe!).
|
1044
|
+
* @return [mrb_value] mruby function value.
|
1045
|
+
*/
|
1046
|
+
MRB_API mrb_value mrb_funcall(mrb_state *mrb, mrb_value val, const char *name, mrb_int argc, ...);
|
1047
|
+
MRB_API mrb_value mrb_funcall_id(mrb_state *mrb, mrb_value val, mrb_sym mid, mrb_int argc, ...);
|
1048
|
+
/**
|
1049
|
+
* Call existing ruby functions. This is basically the type safe version of mrb_funcall.
|
1050
|
+
*
|
1051
|
+
* #include <stdio.h>
|
1052
|
+
* #include <mruby.h>
|
1053
|
+
* #include "mruby/compile.h"
|
1054
|
+
* int
|
1055
|
+
* main()
|
1056
|
+
* {
|
1057
|
+
* mrb_state *mrb = mrb_open();
|
1058
|
+
* mrb_value obj = mrb_fixnum_value(1);
|
1059
|
+
*
|
1060
|
+
* if (!mrb) { }
|
1061
|
+
*
|
1062
|
+
* FILE *fp = fopen("test.rb","r");
|
1063
|
+
* mrb_value obj = mrb_load_file(mrb,fp);
|
1064
|
+
* mrb_funcall_argv(mrb, obj, MRB_SYM(method_name), 1, &obj); // Calling ruby function from test.rb.
|
1065
|
+
* fclose(fp);
|
1066
|
+
* mrb_close(mrb);
|
1067
|
+
* }
|
1068
|
+
* @param mrb The current mruby state.
|
1069
|
+
* @param val A reference to an mruby value.
|
1070
|
+
* @param name_sym The symbol representing the method.
|
1071
|
+
* @param argc The number of arguments the method has.
|
1072
|
+
* @param obj Pointer to the object.
|
1073
|
+
* @return [mrb_value] mrb_value mruby function value.
|
1074
|
+
* @see mrb_funcall
|
1075
|
+
*/
|
1076
|
+
MRB_API mrb_value mrb_funcall_argv(mrb_state *mrb, mrb_value val, mrb_sym name, mrb_int argc, const mrb_value *argv);
|
1077
|
+
/**
|
1078
|
+
* Call existing ruby functions with a block.
|
1079
|
+
*/
|
1080
|
+
MRB_API mrb_value mrb_funcall_with_block(mrb_state *mrb, mrb_value val, mrb_sym name, mrb_int argc, const mrb_value *argv, mrb_value block);
|
1081
|
+
/**
|
1082
|
+
* Create a symbol from C string. But usually it's better to use MRB_SYM,
|
1083
|
+
* MRB_OPSYM, MRB_CVSYM, MRB_IVSYM, MRB_SYM_B, MRB_SYM_Q, MRB_SYM_E macros.
|
1084
|
+
*
|
1085
|
+
* Example:
|
1086
|
+
*
|
1087
|
+
* # Ruby style:
|
1088
|
+
* :pizza # => :pizza
|
1089
|
+
*
|
1090
|
+
* // C style:
|
1091
|
+
* mrb_sym sym1 = mrb_intern_lit(mrb, "pizza"); // => :pizza
|
1092
|
+
* mrb_sym sym2 = MRB_SYM(pizza); // => :pizza
|
1093
|
+
* mrb_sym sym3 = MRB_SYM_Q(pizza); // => :pizza?
|
1094
|
+
*
|
1095
|
+
* @param mrb The current mruby state.
|
1096
|
+
* @param str The string to be symbolized
|
1097
|
+
* @return [mrb_sym] mrb_sym A symbol.
|
1098
|
+
*/
|
1099
|
+
MRB_API mrb_sym mrb_intern_cstr(mrb_state *mrb, const char* str);
|
1100
|
+
MRB_API mrb_sym mrb_intern(mrb_state*,const char*,size_t);
|
1101
|
+
MRB_API mrb_sym mrb_intern_static(mrb_state*,const char*,size_t);
|
1102
|
+
#define mrb_intern_lit(mrb, lit) mrb_intern_static(mrb, (lit ""), mrb_strlen_lit(lit))
|
1103
|
+
MRB_API mrb_sym mrb_intern_str(mrb_state*,mrb_value);
|
1104
|
+
/* mrb_intern_check series functions returns 0 if the symbol is not defined */
|
1105
|
+
MRB_API mrb_sym mrb_intern_check_cstr(mrb_state*,const char*);
|
1106
|
+
MRB_API mrb_sym mrb_intern_check(mrb_state*,const char*,size_t);
|
1107
|
+
MRB_API mrb_sym mrb_intern_check_str(mrb_state*,mrb_value);
|
1108
|
+
/* mrb_check_intern series functions returns nil if the symbol is not defined */
|
1109
|
+
/* otherwise returns mrb_value */
|
1110
|
+
MRB_API mrb_value mrb_check_intern_cstr(mrb_state*,const char*);
|
1111
|
+
MRB_API mrb_value mrb_check_intern(mrb_state*,const char*,size_t);
|
1112
|
+
MRB_API mrb_value mrb_check_intern_str(mrb_state*,mrb_value);
|
1113
|
+
MRB_API const char *mrb_sym_name(mrb_state*,mrb_sym);
|
1114
|
+
MRB_API const char *mrb_sym_name_len(mrb_state*,mrb_sym,mrb_int*);
|
1115
|
+
MRB_API const char *mrb_sym_dump(mrb_state*,mrb_sym);
|
1116
|
+
MRB_API mrb_value mrb_sym_str(mrb_state*,mrb_sym);
|
1117
|
+
#define mrb_sym2name(mrb,sym) mrb_sym_name(mrb,sym)
|
1118
|
+
#define mrb_sym2name_len(mrb,sym,len) mrb_sym_name_len(mrb,sym,len)
|
1119
|
+
#define mrb_sym2str(mrb,sym) mrb_sym_str(mrb,sym)
|
1120
|
+
|
1121
|
+
MRB_API void *mrb_malloc(mrb_state*, size_t); /* raise RuntimeError if no mem */
|
1122
|
+
MRB_API void *mrb_calloc(mrb_state*, size_t, size_t); /* ditto */
|
1123
|
+
MRB_API void *mrb_realloc(mrb_state*, void*, size_t); /* ditto */
|
1124
|
+
MRB_API void *mrb_realloc_simple(mrb_state*, void*, size_t); /* return NULL if no memory available */
|
1125
|
+
MRB_API void *mrb_malloc_simple(mrb_state*, size_t); /* return NULL if no memory available */
|
1126
|
+
MRB_API struct RBasic *mrb_obj_alloc(mrb_state*, enum mrb_vtype, struct RClass*);
|
1127
|
+
MRB_API void mrb_free(mrb_state*, void*);
|
1128
|
+
|
1129
|
+
MRB_API mrb_value mrb_str_new(mrb_state *mrb, const char *p, size_t len);
|
1130
|
+
|
1131
|
+
/**
|
1132
|
+
* Turns a C string into a Ruby string value.
|
1133
|
+
*/
|
1134
|
+
MRB_API mrb_value mrb_str_new_cstr(mrb_state*, const char*);
|
1135
|
+
MRB_API mrb_value mrb_str_new_static(mrb_state *mrb, const char *p, size_t len);
|
1136
|
+
#define mrb_str_new_lit(mrb, lit) mrb_str_new_static(mrb, (lit), mrb_strlen_lit(lit))
|
1137
|
+
|
1138
|
+
MRB_API mrb_value mrb_obj_freeze(mrb_state*, mrb_value);
|
1139
|
+
#define mrb_str_new_frozen(mrb,p,len) mrb_obj_freeze(mrb,mrb_str_new(mrb,p,len))
|
1140
|
+
#define mrb_str_new_cstr_frozen(mrb,p) mrb_obj_freeze(mrb,mrb_str_new_cstr(mrb,p))
|
1141
|
+
#define mrb_str_new_static_frozen(mrb,p,len) mrb_obj_freeze(mrb,mrb_str_new_static(mrb,p,len))
|
1142
|
+
#define mrb_str_new_lit_frozen(mrb,lit) mrb_obj_freeze(mrb,mrb_str_new_lit(mrb,lit))
|
1143
|
+
|
1144
|
+
#ifdef _WIN32
|
1145
|
+
MRB_API char* mrb_utf8_from_locale(const char *p, int len);
|
1146
|
+
MRB_API char* mrb_locale_from_utf8(const char *p, int len);
|
1147
|
+
#define mrb_locale_free(p) free(p)
|
1148
|
+
#define mrb_utf8_free(p) free(p)
|
1149
|
+
#else
|
1150
|
+
#define mrb_utf8_from_locale(p, l) ((char*)(p))
|
1151
|
+
#define mrb_locale_from_utf8(p, l) ((char*)(p))
|
1152
|
+
#define mrb_locale_free(p)
|
1153
|
+
#define mrb_utf8_free(p)
|
1154
|
+
#endif
|
1155
|
+
|
1156
|
+
/**
|
1157
|
+
* Creates new mrb_state.
|
1158
|
+
*
|
1159
|
+
* @return
|
1160
|
+
* Pointer to the newly created mrb_state.
|
1161
|
+
*/
|
1162
|
+
MRB_API mrb_state* mrb_open(void);
|
1163
|
+
|
1164
|
+
/**
|
1165
|
+
* Create new mrb_state with custom allocators.
|
1166
|
+
*
|
1167
|
+
* @param f
|
1168
|
+
* Reference to the allocation function.
|
1169
|
+
* @param ud
|
1170
|
+
* User data will be passed to custom allocator f.
|
1171
|
+
* If user data isn't required just pass NULL.
|
1172
|
+
* @return
|
1173
|
+
* Pointer to the newly created mrb_state.
|
1174
|
+
*/
|
1175
|
+
MRB_API mrb_state* mrb_open_allocf(mrb_allocf f, void *ud);
|
1176
|
+
|
1177
|
+
/**
|
1178
|
+
* Create new mrb_state with just the MRuby core
|
1179
|
+
*
|
1180
|
+
* @param f
|
1181
|
+
* Reference to the allocation function.
|
1182
|
+
* Use mrb_default_allocf for the default
|
1183
|
+
* @param ud
|
1184
|
+
* User data will be passed to custom allocator f.
|
1185
|
+
* If user data isn't required just pass NULL.
|
1186
|
+
* @return
|
1187
|
+
* Pointer to the newly created mrb_state.
|
1188
|
+
*/
|
1189
|
+
MRB_API mrb_state* mrb_open_core(mrb_allocf f, void *ud);
|
1190
|
+
|
1191
|
+
/**
|
1192
|
+
* Closes and frees a mrb_state.
|
1193
|
+
*
|
1194
|
+
* @param mrb
|
1195
|
+
* Pointer to the mrb_state to be closed.
|
1196
|
+
*/
|
1197
|
+
MRB_API void mrb_close(mrb_state *mrb);
|
1198
|
+
|
1199
|
+
/**
|
1200
|
+
* The default allocation function.
|
1201
|
+
*
|
1202
|
+
* @see mrb_allocf
|
1203
|
+
*/
|
1204
|
+
MRB_API void* mrb_default_allocf(mrb_state*, void*, size_t, void*);
|
1205
|
+
|
1206
|
+
MRB_API mrb_value mrb_top_self(mrb_state *mrb);
|
1207
|
+
MRB_API mrb_value mrb_top_run(mrb_state *mrb, const struct RProc *proc, mrb_value self, mrb_int stack_keep);
|
1208
|
+
MRB_API mrb_value mrb_vm_run(mrb_state *mrb, const struct RProc *proc, mrb_value self, mrb_int stack_keep);
|
1209
|
+
MRB_API mrb_value mrb_vm_exec(mrb_state *mrb, const struct RProc *proc, const mrb_code *iseq);
|
1210
|
+
/* compatibility macros */
|
1211
|
+
#define mrb_toplevel_run_keep(m,p,k) mrb_top_run((m),(p),mrb_top_self(m),(k))
|
1212
|
+
#define mrb_toplevel_run(m,p) mrb_toplevel_run_keep((m),(p),0)
|
1213
|
+
#define mrb_context_run(m,p,s,k) mrb_vm_run((m),(p),(s),(k))
|
1214
|
+
|
1215
|
+
MRB_API void mrb_p(mrb_state*, mrb_value);
|
1216
|
+
MRB_API mrb_int mrb_obj_id(mrb_value obj);
|
1217
|
+
MRB_API mrb_sym mrb_obj_to_sym(mrb_state *mrb, mrb_value name);
|
1218
|
+
|
1219
|
+
MRB_API mrb_bool mrb_obj_eq(mrb_state *mrb, mrb_value a, mrb_value b);
|
1220
|
+
MRB_API mrb_bool mrb_obj_equal(mrb_state *mrb, mrb_value a, mrb_value b);
|
1221
|
+
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
|
+
#ifndef MRB_NO_FLOAT
|
1225
|
+
MRB_API mrb_value mrb_Float(mrb_state *mrb, mrb_value val);
|
1226
|
+
#endif
|
1227
|
+
MRB_API mrb_value mrb_inspect(mrb_state *mrb, mrb_value obj);
|
1228
|
+
MRB_API mrb_bool mrb_eql(mrb_state *mrb, mrb_value obj1, mrb_value obj2);
|
1229
|
+
/* mrb_cmp(mrb, obj1, obj2): 1:0:-1; -2 for error */
|
1230
|
+
MRB_API mrb_int mrb_cmp(mrb_state *mrb, mrb_value obj1, mrb_value obj2);
|
1231
|
+
|
1232
|
+
MRB_INLINE int
|
1233
|
+
mrb_gc_arena_save(mrb_state *mrb)
|
1234
|
+
{
|
1235
|
+
return mrb->gc.arena_idx;
|
1236
|
+
}
|
1237
|
+
|
1238
|
+
MRB_INLINE void
|
1239
|
+
mrb_gc_arena_restore(mrb_state *mrb, int idx)
|
1240
|
+
{
|
1241
|
+
mrb->gc.arena_idx = idx;
|
1242
|
+
}
|
1243
|
+
|
1244
|
+
MRB_API void mrb_garbage_collect(mrb_state*);
|
1245
|
+
MRB_API void mrb_full_gc(mrb_state*);
|
1246
|
+
MRB_API void mrb_incremental_gc(mrb_state *);
|
1247
|
+
MRB_API void mrb_gc_mark(mrb_state*,struct RBasic*);
|
1248
|
+
#define mrb_gc_mark_value(mrb,val) do {\
|
1249
|
+
if (!mrb_immediate_p(val)) mrb_gc_mark((mrb), mrb_basic_ptr(val)); \
|
1250
|
+
} while (0)
|
1251
|
+
MRB_API void mrb_field_write_barrier(mrb_state *, struct RBasic*, struct RBasic*);
|
1252
|
+
#define mrb_field_write_barrier_value(mrb, obj, val) do{\
|
1253
|
+
if (!mrb_immediate_p(val)) mrb_field_write_barrier((mrb), (obj), mrb_basic_ptr(val)); \
|
1254
|
+
} while (0)
|
1255
|
+
MRB_API void mrb_write_barrier(mrb_state *, struct RBasic*);
|
1256
|
+
|
1257
|
+
MRB_API mrb_value mrb_type_convert(mrb_state *mrb, mrb_value val, enum mrb_vtype type, mrb_sym method);
|
1258
|
+
#define mrb_convert_type(mrb, val, type, tname, method) mrb_type_convert(mrb, val, type, mrb_intern_lit(mrb, method))
|
1259
|
+
MRB_API mrb_value mrb_type_convert_check(mrb_state *mrb, mrb_value val, enum mrb_vtype type, mrb_sym method);
|
1260
|
+
#define mrb_check_convert_type(mrb, val, type, tname, method) mrb_type_convert_check(mrb, val, type, mrb_intern_lit(mrb, method))
|
1261
|
+
|
1262
|
+
MRB_API mrb_value mrb_any_to_s(mrb_state *mrb, mrb_value obj);
|
1263
|
+
MRB_API const char * mrb_obj_classname(mrb_state *mrb, mrb_value obj);
|
1264
|
+
MRB_API struct RClass* mrb_obj_class(mrb_state *mrb, mrb_value obj);
|
1265
|
+
MRB_API mrb_value mrb_class_path(mrb_state *mrb, struct RClass *c);
|
1266
|
+
MRB_API mrb_bool mrb_obj_is_kind_of(mrb_state *mrb, mrb_value obj, struct RClass *c);
|
1267
|
+
MRB_API mrb_value mrb_obj_inspect(mrb_state *mrb, mrb_value self);
|
1268
|
+
MRB_API mrb_value mrb_obj_clone(mrb_state *mrb, mrb_value self);
|
1269
|
+
|
1270
|
+
#ifndef ISPRINT
|
1271
|
+
#define ISASCII(c) ((unsigned)(c) <= 0x7f)
|
1272
|
+
#define ISPRINT(c) (((unsigned)(c) - 0x20) < 0x5f)
|
1273
|
+
#define ISSPACE(c) ((c) == ' ' || (unsigned)(c) - '\t' < 5)
|
1274
|
+
#define ISUPPER(c) (((unsigned)(c) - 'A') < 26)
|
1275
|
+
#define ISLOWER(c) (((unsigned)(c) - 'a') < 26)
|
1276
|
+
#define ISALPHA(c) ((((unsigned)(c) | 0x20) - 'a') < 26)
|
1277
|
+
#define ISDIGIT(c) (((unsigned)(c) - '0') < 10)
|
1278
|
+
#define ISXDIGIT(c) (ISDIGIT(c) || ((unsigned)(c) | 0x20) - 'a' < 6)
|
1279
|
+
#define ISALNUM(c) (ISALPHA(c) || ISDIGIT(c))
|
1280
|
+
#define ISBLANK(c) ((c) == ' ' || (c) == '\t')
|
1281
|
+
#define ISCNTRL(c) ((unsigned)(c) < 0x20 || (c) == 0x7f)
|
1282
|
+
#define TOUPPER(c) (ISLOWER(c) ? ((c) & 0x5f) : (c))
|
1283
|
+
#define TOLOWER(c) (ISUPPER(c) ? ((c) | 0x20) : (c))
|
1284
|
+
#endif
|
1285
|
+
|
1286
|
+
MRB_API mrb_value mrb_exc_new(mrb_state *mrb, struct RClass *c, const char *ptr, size_t len);
|
1287
|
+
MRB_API mrb_noreturn void mrb_exc_raise(mrb_state *mrb, mrb_value exc);
|
1288
|
+
|
1289
|
+
MRB_API mrb_noreturn void mrb_raise(mrb_state *mrb, struct RClass *c, const char *msg);
|
1290
|
+
MRB_API mrb_noreturn void mrb_raisef(mrb_state *mrb, struct RClass *c, const char *fmt, ...);
|
1291
|
+
MRB_API mrb_noreturn void mrb_name_error(mrb_state *mrb, mrb_sym id, const char *fmt, ...);
|
1292
|
+
MRB_API mrb_noreturn void mrb_frozen_error(mrb_state *mrb, void *frozen_obj);
|
1293
|
+
MRB_API mrb_noreturn void mrb_argnum_error(mrb_state *mrb, mrb_int argc, int min, int max);
|
1294
|
+
MRB_API void mrb_warn(mrb_state *mrb, const char *fmt, ...);
|
1295
|
+
MRB_API mrb_noreturn void mrb_bug(mrb_state *mrb, const char *fmt, ...);
|
1296
|
+
MRB_API void mrb_print_backtrace(mrb_state *mrb);
|
1297
|
+
MRB_API void mrb_print_error(mrb_state *mrb);
|
1298
|
+
/* function for `raisef` formatting */
|
1299
|
+
MRB_API mrb_value mrb_vformat(mrb_state *mrb, const char *format, va_list ap);
|
1300
|
+
|
1301
|
+
/* macros to get typical exception objects
|
1302
|
+
note:
|
1303
|
+
+ those E_* macros requires mrb_state* variable named mrb.
|
1304
|
+
+ exception objects obtained from those macros are local to mrb
|
1305
|
+
*/
|
1306
|
+
#define MRB_ERROR_SYM(sym) mrb_intern_lit(mrb, #sym)
|
1307
|
+
#define E_RUNTIME_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(RuntimeError))
|
1308
|
+
#define E_TYPE_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(TypeError))
|
1309
|
+
#define E_ZERODIV_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(ZeroDivisionError))
|
1310
|
+
#define E_ARGUMENT_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(ArgumentError))
|
1311
|
+
#define E_INDEX_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(IndexError))
|
1312
|
+
#define E_RANGE_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(RangeError))
|
1313
|
+
#define E_NAME_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(NameError))
|
1314
|
+
#define E_NOMETHOD_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(NoMethodError))
|
1315
|
+
#define E_SCRIPT_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(ScriptError))
|
1316
|
+
#define E_SYNTAX_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(SyntaxError))
|
1317
|
+
#define E_LOCALJUMP_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(LocalJumpError))
|
1318
|
+
#define E_REGEXP_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(RegexpError))
|
1319
|
+
#define E_FROZEN_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(FrozenError))
|
1320
|
+
#define E_NOTIMP_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(NotImplementedError))
|
1321
|
+
#define E_KEY_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(KeyError))
|
1322
|
+
#ifndef MRB_NO_FLOAT
|
1323
|
+
# define E_FLOATDOMAIN_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(FloatDomainError))
|
1324
|
+
#endif
|
1325
|
+
|
1326
|
+
MRB_API mrb_value mrb_yield(mrb_state *mrb, mrb_value b, mrb_value arg);
|
1327
|
+
MRB_API mrb_value mrb_yield_argv(mrb_state *mrb, mrb_value b, mrb_int argc, const mrb_value *argv);
|
1328
|
+
MRB_API mrb_value mrb_yield_with_class(mrb_state *mrb, mrb_value b, mrb_int argc, const mrb_value *argv, mrb_value self, struct RClass *c);
|
1329
|
+
|
1330
|
+
/* continue execution to the proc */
|
1331
|
+
/* this function should always be called as the last function of a method */
|
1332
|
+
/* e.g. return mrb_yield_cont(mrb, proc, self, argc, argv); */
|
1333
|
+
mrb_value mrb_yield_cont(mrb_state *mrb, mrb_value b, mrb_value self, mrb_int argc, const mrb_value *argv);
|
1334
|
+
|
1335
|
+
/* mrb_gc_protect() leaves the object in the arena */
|
1336
|
+
MRB_API void mrb_gc_protect(mrb_state *mrb, mrb_value obj);
|
1337
|
+
/* mrb_gc_register() keeps the object from GC. */
|
1338
|
+
MRB_API void mrb_gc_register(mrb_state *mrb, mrb_value obj);
|
1339
|
+
/* mrb_gc_unregister() removes the object from GC root. */
|
1340
|
+
MRB_API void mrb_gc_unregister(mrb_state *mrb, mrb_value obj);
|
1341
|
+
|
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))
|
1344
|
+
/* 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
|
+
MRB_API void mrb_check_type(mrb_state *mrb, mrb_value x, enum mrb_vtype t);
|
1347
|
+
|
1348
|
+
MRB_INLINE void mrb_check_frozen(mrb_state *mrb, void *o)
|
1349
|
+
{
|
1350
|
+
if (mrb_frozen_p((struct RBasic*)o)) mrb_frozen_error(mrb, o);
|
1351
|
+
}
|
1352
|
+
|
1353
|
+
MRB_API void mrb_define_alias(mrb_state *mrb, struct RClass *c, const char *a, const char *b);
|
1354
|
+
MRB_API void mrb_define_alias_id(mrb_state *mrb, struct RClass *c, mrb_sym a, mrb_sym b);
|
1355
|
+
MRB_API const char *mrb_class_name(mrb_state *mrb, struct RClass* klass);
|
1356
|
+
MRB_API void mrb_define_global_const(mrb_state *mrb, const char *name, mrb_value val);
|
1357
|
+
|
1358
|
+
MRB_API mrb_value mrb_attr_get(mrb_state *mrb, mrb_value obj, mrb_sym id);
|
1359
|
+
|
1360
|
+
MRB_API mrb_bool mrb_respond_to(mrb_state *mrb, mrb_value obj, mrb_sym mid);
|
1361
|
+
MRB_API mrb_bool mrb_obj_is_instance_of(mrb_state *mrb, mrb_value obj, struct RClass* c);
|
1362
|
+
MRB_API mrb_bool mrb_func_basic_p(mrb_state *mrb, mrb_value obj, mrb_sym mid, mrb_func_t func);
|
1363
|
+
|
1364
|
+
|
1365
|
+
/**
|
1366
|
+
* Resume a Fiber
|
1367
|
+
*
|
1368
|
+
* Implemented in mruby-fiber
|
1369
|
+
*/
|
1370
|
+
MRB_API mrb_value mrb_fiber_resume(mrb_state *mrb, mrb_value fib, mrb_int argc, const mrb_value *argv);
|
1371
|
+
|
1372
|
+
/**
|
1373
|
+
* Yield a Fiber
|
1374
|
+
*
|
1375
|
+
* Implemented in mruby-fiber
|
1376
|
+
*/
|
1377
|
+
MRB_API mrb_value mrb_fiber_yield(mrb_state *mrb, mrb_int argc, const mrb_value *argv);
|
1378
|
+
|
1379
|
+
/**
|
1380
|
+
* Check if a Fiber is alive
|
1381
|
+
*
|
1382
|
+
* Implemented in mruby-fiber
|
1383
|
+
*/
|
1384
|
+
MRB_API mrb_value mrb_fiber_alive_p(mrb_state *mrb, mrb_value fib);
|
1385
|
+
|
1386
|
+
/**
|
1387
|
+
* FiberError reference
|
1388
|
+
*
|
1389
|
+
* Implemented in mruby-fiber
|
1390
|
+
*/
|
1391
|
+
#define E_FIBER_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(FiberError))
|
1392
|
+
MRB_API void mrb_stack_extend(mrb_state*, mrb_int);
|
1393
|
+
|
1394
|
+
/* memory pool implementation */
|
1395
|
+
typedef struct mrb_pool mrb_pool;
|
1396
|
+
MRB_API struct mrb_pool* mrb_pool_open(mrb_state*);
|
1397
|
+
MRB_API void mrb_pool_close(struct mrb_pool*);
|
1398
|
+
MRB_API void* mrb_pool_alloc(struct mrb_pool*, size_t);
|
1399
|
+
MRB_API void* mrb_pool_realloc(struct mrb_pool*, void*, size_t oldlen, size_t newlen);
|
1400
|
+
MRB_API mrb_bool mrb_pool_can_realloc(struct mrb_pool*, void*, size_t);
|
1401
|
+
/* temporary memory allocation, only effective while GC arena is kept */
|
1402
|
+
MRB_API void* mrb_alloca(mrb_state *mrb, size_t);
|
1403
|
+
|
1404
|
+
MRB_API void mrb_state_atexit(mrb_state *mrb, mrb_atexit_func func);
|
1405
|
+
|
1406
|
+
MRB_API void mrb_show_version(mrb_state *mrb);
|
1407
|
+
MRB_API void mrb_show_copyright(mrb_state *mrb);
|
1408
|
+
|
1409
|
+
MRB_API mrb_value mrb_format(mrb_state *mrb, const char *format, ...);
|
1410
|
+
|
1411
|
+
#ifdef MRB_PRESYM_SCANNING
|
1412
|
+
# include <mruby/presym/scanning.h>
|
1413
|
+
#endif
|
1414
|
+
|
1415
|
+
#if 0
|
1416
|
+
/* memcpy and memset does not work with gdb reverse-next on my box */
|
1417
|
+
/* use naive memcpy and memset instead */
|
1418
|
+
#undef memcpy
|
1419
|
+
#undef memset
|
1420
|
+
static void*
|
1421
|
+
mrbmemcpy(void *dst, const void *src, size_t n)
|
1422
|
+
{
|
1423
|
+
char *d = (char*)dst;
|
1424
|
+
const char *s = (const char*)src;
|
1425
|
+
while (n--)
|
1426
|
+
*d++ = *s++;
|
1427
|
+
return d;
|
1428
|
+
}
|
1429
|
+
#define memcpy(a,b,c) mrbmemcpy(a,b,c)
|
1430
|
+
|
1431
|
+
static void*
|
1432
|
+
mrbmemset(void *s, int c, size_t n)
|
1433
|
+
{
|
1434
|
+
char *t = (char*)s;
|
1435
|
+
while (n--)
|
1436
|
+
*t++ = c;
|
1437
|
+
return s;
|
1438
|
+
}
|
1439
|
+
#define memset(a,b,c) mrbmemset(a,b,c)
|
1440
|
+
#endif
|
1441
|
+
|
1442
|
+
MRB_END_DECL
|
1443
|
+
|
1444
|
+
#endif /* MRUBY_H */
|