ruby2d 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/assets/README.md +8 -0
- data/assets/ios/Assets.xcassets/AppIcon.appiconset/Contents.json +98 -0
- data/assets/ios/Assets.xcassets/Contents.json +6 -0
- data/assets/ios/Base.lproj/LaunchScreen.storyboard +27 -0
- data/assets/ios/Info.plist +43 -0
- data/assets/ios/MRuby.framework/Headers/mrbconf.h +145 -0
- data/assets/ios/MRuby.framework/Headers/mruby.h +1279 -0
- data/assets/ios/MRuby.framework/Headers/mruby/array.h +279 -0
- data/assets/ios/MRuby.framework/Headers/mruby/boxing_nan.h +102 -0
- data/assets/ios/MRuby.framework/Headers/mruby/boxing_no.h +56 -0
- data/assets/ios/MRuby.framework/Headers/mruby/boxing_word.h +136 -0
- data/assets/ios/MRuby.framework/Headers/mruby/class.h +94 -0
- data/assets/ios/MRuby.framework/Headers/mruby/common.h +72 -0
- data/assets/ios/MRuby.framework/Headers/mruby/compile.h +194 -0
- data/assets/ios/MRuby.framework/Headers/mruby/data.h +75 -0
- data/assets/ios/MRuby.framework/Headers/mruby/debug.h +66 -0
- data/assets/ios/MRuby.framework/Headers/mruby/dump.h +196 -0
- data/assets/ios/MRuby.framework/Headers/mruby/error.h +75 -0
- data/assets/ios/MRuby.framework/Headers/mruby/gc.h +91 -0
- data/assets/ios/MRuby.framework/Headers/mruby/hash.h +182 -0
- data/assets/ios/MRuby.framework/Headers/mruby/irep.h +62 -0
- data/assets/ios/MRuby.framework/Headers/mruby/istruct.h +47 -0
- data/assets/ios/MRuby.framework/Headers/mruby/khash.h +274 -0
- data/assets/ios/MRuby.framework/Headers/mruby/numeric.h +161 -0
- data/assets/ios/MRuby.framework/Headers/mruby/object.h +45 -0
- data/assets/ios/MRuby.framework/Headers/mruby/opcode.h +161 -0
- data/assets/ios/MRuby.framework/Headers/mruby/proc.h +131 -0
- data/assets/ios/MRuby.framework/Headers/mruby/range.h +49 -0
- data/assets/ios/MRuby.framework/Headers/mruby/re.h +16 -0
- data/assets/ios/MRuby.framework/Headers/mruby/string.h +440 -0
- data/assets/ios/MRuby.framework/Headers/mruby/throw.h +55 -0
- data/assets/ios/MRuby.framework/Headers/mruby/value.h +309 -0
- data/assets/ios/MRuby.framework/Headers/mruby/variable.h +138 -0
- data/assets/ios/MRuby.framework/Headers/mruby/version.h +110 -0
- data/assets/ios/MRuby.framework/Info.plist +20 -0
- data/assets/ios/MRuby.framework/MRuby +0 -0
- data/assets/ios/MyApp.xcodeproj/project.pbxproj +362 -0
- data/assets/ios/MyApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- data/assets/ios/MyApp.xcodeproj/project.xcworkspace/xcshareddata/MyApp.xcscmblueprint +30 -0
- data/assets/ios/MyApp.xcodeproj/project.xcworkspace/xcuserdata/Tom.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- data/assets/ios/MyApp.xcodeproj/xcuserdata/Tom.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
- data/assets/ios/main.c +1 -0
- data/assets/opal.js +8434 -6329
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Content.imageset/Contents.json +12 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Contents.json +6 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Contents.json +17 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Content.imageset/Contents.json +12 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Contents.json +6 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json +12 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Contents.json +6 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Content.imageset/Contents.json +12 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Contents.json +6 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Contents.json +17 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Content.imageset/Contents.json +12 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Contents.json +6 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json +12 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Contents.json +6 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Contents.json +32 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Top Shelf Image Wide.imageset/Contents.json +12 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Top Shelf Image.imageset/Contents.json +12 -0
- data/assets/tvos/Assets.xcassets/Contents.json +6 -0
- data/assets/tvos/Assets.xcassets/LaunchImage.launchimage/Contents.json +15 -0
- data/assets/tvos/Info.plist +30 -0
- data/assets/tvos/MRuby.framework/Headers/mrbconf.h +145 -0
- data/assets/tvos/MRuby.framework/Headers/mruby.h +1279 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/array.h +279 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/boxing_nan.h +102 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/boxing_no.h +56 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/boxing_word.h +136 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/class.h +94 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/common.h +72 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/compile.h +194 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/data.h +75 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/debug.h +66 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/dump.h +196 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/error.h +75 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/gc.h +91 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/hash.h +182 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/irep.h +62 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/istruct.h +47 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/khash.h +274 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/numeric.h +161 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/object.h +45 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/opcode.h +161 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/proc.h +131 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/range.h +49 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/re.h +16 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/string.h +440 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/throw.h +55 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/value.h +309 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/variable.h +138 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/version.h +110 -0
- data/assets/tvos/MRuby.framework/Info.plist +20 -0
- data/assets/tvos/MRuby.framework/MRuby +0 -0
- data/assets/tvos/MyApp.xcodeproj/project.pbxproj +344 -0
- data/assets/tvos/MyApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- data/assets/tvos/MyApp.xcodeproj/project.xcworkspace/xcshareddata/MyApp.xcscmblueprint +30 -0
- data/assets/tvos/main.c +1 -0
- data/bin/ruby2d +219 -64
- data/ext/ruby2d/extconf.rb +1 -1
- data/ext/ruby2d/ruby2d.c +117 -19
- data/lib/ruby2d/color.rb +1 -1
- data/lib/ruby2d/version.rb +1 -1
- data/lib/ruby2d/window.rb +16 -10
- metadata +102 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b3248849ba536b5f8b806a92b6020c9177feb4b8415241cc5579240b9d25f771
|
4
|
+
data.tar.gz: f934d3eaef436fd21de2a120fc4ec392e670f3e123865b3aea251d2b5f1f4459
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f844b95a670393b87a606bfd098b9abbd2f2758a3e255e30527339202e46affc2cc9caedc8c3fcdd4a486cdefd06d4cab7af579cacdc9a38e86fcb8e97d8a603
|
7
|
+
data.tar.gz: ed7598cce5629acf38a346b95feb86e1c9b402cc380448f2f031b4f2c6c4c0ed8eb3ac633e8c1e4a0caf1d8ef003ec3ac8b50b387154e075287ac02c5f9459ff
|
data/assets/README.md
CHANGED
@@ -1 +1,9 @@
|
|
1
1
|
# Assets for the Ruby 2D gem
|
2
|
+
|
3
|
+
This repo contains:
|
4
|
+
- Xcode projects for iOS and tvOS, derived from the [Simple 2D deps](https://github.com/simple2d/deps/tree/master/xcode)
|
5
|
+
- iOS and tvOS frameworks from [`mruby-frameworks`](https://github.com/ruby2d/mruby-frameworks)
|
6
|
+
- [Simple2D.js](https://github.com/simple2d/simple2d.js)
|
7
|
+
- The [Opal](http://opalrb.com) library generated using, for example, `opal --compile app.rb > app.js`
|
8
|
+
- An [HTML template](template.html) for web-based apps
|
9
|
+
- The [Ruby 2D logo](https://github.com/ruby2d/logo) icon
|
@@ -0,0 +1,98 @@
|
|
1
|
+
{
|
2
|
+
"images" : [
|
3
|
+
{
|
4
|
+
"idiom" : "iphone",
|
5
|
+
"size" : "20x20",
|
6
|
+
"scale" : "2x"
|
7
|
+
},
|
8
|
+
{
|
9
|
+
"idiom" : "iphone",
|
10
|
+
"size" : "20x20",
|
11
|
+
"scale" : "3x"
|
12
|
+
},
|
13
|
+
{
|
14
|
+
"idiom" : "iphone",
|
15
|
+
"size" : "29x29",
|
16
|
+
"scale" : "2x"
|
17
|
+
},
|
18
|
+
{
|
19
|
+
"idiom" : "iphone",
|
20
|
+
"size" : "29x29",
|
21
|
+
"scale" : "3x"
|
22
|
+
},
|
23
|
+
{
|
24
|
+
"idiom" : "iphone",
|
25
|
+
"size" : "40x40",
|
26
|
+
"scale" : "2x"
|
27
|
+
},
|
28
|
+
{
|
29
|
+
"idiom" : "iphone",
|
30
|
+
"size" : "40x40",
|
31
|
+
"scale" : "3x"
|
32
|
+
},
|
33
|
+
{
|
34
|
+
"idiom" : "iphone",
|
35
|
+
"size" : "60x60",
|
36
|
+
"scale" : "2x"
|
37
|
+
},
|
38
|
+
{
|
39
|
+
"idiom" : "iphone",
|
40
|
+
"size" : "60x60",
|
41
|
+
"scale" : "3x"
|
42
|
+
},
|
43
|
+
{
|
44
|
+
"idiom" : "ipad",
|
45
|
+
"size" : "20x20",
|
46
|
+
"scale" : "1x"
|
47
|
+
},
|
48
|
+
{
|
49
|
+
"idiom" : "ipad",
|
50
|
+
"size" : "20x20",
|
51
|
+
"scale" : "2x"
|
52
|
+
},
|
53
|
+
{
|
54
|
+
"idiom" : "ipad",
|
55
|
+
"size" : "29x29",
|
56
|
+
"scale" : "1x"
|
57
|
+
},
|
58
|
+
{
|
59
|
+
"idiom" : "ipad",
|
60
|
+
"size" : "29x29",
|
61
|
+
"scale" : "2x"
|
62
|
+
},
|
63
|
+
{
|
64
|
+
"idiom" : "ipad",
|
65
|
+
"size" : "40x40",
|
66
|
+
"scale" : "1x"
|
67
|
+
},
|
68
|
+
{
|
69
|
+
"idiom" : "ipad",
|
70
|
+
"size" : "40x40",
|
71
|
+
"scale" : "2x"
|
72
|
+
},
|
73
|
+
{
|
74
|
+
"idiom" : "ipad",
|
75
|
+
"size" : "76x76",
|
76
|
+
"scale" : "1x"
|
77
|
+
},
|
78
|
+
{
|
79
|
+
"idiom" : "ipad",
|
80
|
+
"size" : "76x76",
|
81
|
+
"scale" : "2x"
|
82
|
+
},
|
83
|
+
{
|
84
|
+
"idiom" : "ipad",
|
85
|
+
"size" : "83.5x83.5",
|
86
|
+
"scale" : "2x"
|
87
|
+
},
|
88
|
+
{
|
89
|
+
"idiom" : "ios-marketing",
|
90
|
+
"size" : "1024x1024",
|
91
|
+
"scale" : "1x"
|
92
|
+
}
|
93
|
+
],
|
94
|
+
"info" : {
|
95
|
+
"version" : 1,
|
96
|
+
"author" : "xcode"
|
97
|
+
}
|
98
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
2
|
+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
|
3
|
+
<dependencies>
|
4
|
+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11106"/>
|
5
|
+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
6
|
+
</dependencies>
|
7
|
+
<scenes>
|
8
|
+
<!--View Controller-->
|
9
|
+
<scene sceneID="EHf-IW-A2E">
|
10
|
+
<objects>
|
11
|
+
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
|
12
|
+
<layoutGuides>
|
13
|
+
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
|
14
|
+
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
|
15
|
+
</layoutGuides>
|
16
|
+
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
|
17
|
+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
18
|
+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
19
|
+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
20
|
+
</view>
|
21
|
+
</viewController>
|
22
|
+
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
23
|
+
</objects>
|
24
|
+
<point key="canvasLocation" x="53" y="375"/>
|
25
|
+
</scene>
|
26
|
+
</scenes>
|
27
|
+
</document>
|
@@ -0,0 +1,43 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
3
|
+
<plist version="1.0">
|
4
|
+
<dict>
|
5
|
+
<key>CFBundleDevelopmentRegion</key>
|
6
|
+
<string>en</string>
|
7
|
+
<key>CFBundleExecutable</key>
|
8
|
+
<string>$(EXECUTABLE_NAME)</string>
|
9
|
+
<key>CFBundleIdentifier</key>
|
10
|
+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
11
|
+
<key>CFBundleInfoDictionaryVersion</key>
|
12
|
+
<string>6.0</string>
|
13
|
+
<key>CFBundleName</key>
|
14
|
+
<string>$(PRODUCT_NAME)</string>
|
15
|
+
<key>CFBundlePackageType</key>
|
16
|
+
<string>APPL</string>
|
17
|
+
<key>CFBundleShortVersionString</key>
|
18
|
+
<string>1.0</string>
|
19
|
+
<key>CFBundleVersion</key>
|
20
|
+
<string>1</string>
|
21
|
+
<key>LSRequiresIPhoneOS</key>
|
22
|
+
<true/>
|
23
|
+
<key>UILaunchStoryboardName</key>
|
24
|
+
<string>LaunchScreen</string>
|
25
|
+
<key>UIRequiredDeviceCapabilities</key>
|
26
|
+
<array>
|
27
|
+
<string>armv7</string>
|
28
|
+
</array>
|
29
|
+
<key>UISupportedInterfaceOrientations</key>
|
30
|
+
<array>
|
31
|
+
<string>UIInterfaceOrientationPortrait</string>
|
32
|
+
<string>UIInterfaceOrientationLandscapeLeft</string>
|
33
|
+
<string>UIInterfaceOrientationLandscapeRight</string>
|
34
|
+
</array>
|
35
|
+
<key>UISupportedInterfaceOrientations~ipad</key>
|
36
|
+
<array>
|
37
|
+
<string>UIInterfaceOrientationPortrait</string>
|
38
|
+
<string>UIInterfaceOrientationPortraitUpsideDown</string>
|
39
|
+
<string>UIInterfaceOrientationLandscapeLeft</string>
|
40
|
+
<string>UIInterfaceOrientationLandscapeRight</string>
|
41
|
+
</array>
|
42
|
+
</dict>
|
43
|
+
</plist>
|
@@ -0,0 +1,145 @@
|
|
1
|
+
/*
|
2
|
+
** mrbconf.h - mruby core configuration
|
3
|
+
**
|
4
|
+
** See Copyright Notice in mruby.h
|
5
|
+
*/
|
6
|
+
|
7
|
+
#ifndef MRUBYCONF_H
|
8
|
+
#define MRUBYCONF_H
|
9
|
+
|
10
|
+
#include <limits.h>
|
11
|
+
#include <stdint.h>
|
12
|
+
|
13
|
+
/* architecture selection: */
|
14
|
+
/* specify -DMRB_32BIT or -DMRB_64BIT to override */
|
15
|
+
#if !defined(MRB_32BIT) && !defined(MRB_64BIT)
|
16
|
+
#if UINT64_MAX == SIZE_MAX
|
17
|
+
#define MRB_64BIT
|
18
|
+
#else
|
19
|
+
#define MRB_32BIT
|
20
|
+
#endif
|
21
|
+
#endif
|
22
|
+
|
23
|
+
#if defined(MRB_32BIT) && defined(MRB_64BIT)
|
24
|
+
#error Cannot build for 32 and 64 bit architecture at the same time
|
25
|
+
#endif
|
26
|
+
|
27
|
+
/* configuration options: */
|
28
|
+
/* add -DMRB_USE_FLOAT to use float instead of double for floating point numbers */
|
29
|
+
//#define MRB_USE_FLOAT
|
30
|
+
|
31
|
+
/* exclude floating point numbers */
|
32
|
+
//#define MRB_WITHOUT_FLOAT
|
33
|
+
|
34
|
+
/* add -DMRB_METHOD_CACHE to use method cache to improve performance */
|
35
|
+
//#define MRB_METHOD_CACHE
|
36
|
+
/* size of the method cache (need to be the power of 2) */
|
37
|
+
//#define MRB_METHOD_CACHE_SIZE (1<<7)
|
38
|
+
|
39
|
+
/* add -DMRB_METHOD_TABLE_INLINE unless platform uses MSB of pointers */
|
40
|
+
//#define MRB_METHOD_TABLE_INLINE
|
41
|
+
/* turn MRB_METHOD_TABLE_INLINE on for linux by default */
|
42
|
+
#if !defined(MRB_METHOD_TABLE_INLINE) && defined(__linux__)
|
43
|
+
# define MRB_METHOD_TABLE_INLINE
|
44
|
+
#endif
|
45
|
+
|
46
|
+
/* add -DMRB_INT16 to use 16bit integer for mrb_int; conflict with MRB_INT64 */
|
47
|
+
//#define MRB_INT16
|
48
|
+
|
49
|
+
/* add -DMRB_INT64 to use 64bit integer for mrb_int; conflict with MRB_INT16 */
|
50
|
+
//#define MRB_INT64
|
51
|
+
|
52
|
+
/* if no specific integer type is chosen */
|
53
|
+
#if !defined(MRB_INT16) && !defined(MRB_INT32) && !defined(MRB_INT64)
|
54
|
+
# if defined(MRB_64BIT) && !defined(MRB_NAN_BOXING)
|
55
|
+
/* Use 64bit integers on 64bit architecture (without MRB_NAN_BOXING) */
|
56
|
+
# define MRB_INT64
|
57
|
+
# else
|
58
|
+
/* Otherwise use 32bit integers */
|
59
|
+
# define MRB_INT32
|
60
|
+
# endif
|
61
|
+
#endif
|
62
|
+
|
63
|
+
/* represent mrb_value in boxed double; conflict with MRB_USE_FLOAT and MRB_WITHOUT_FLOAT */
|
64
|
+
//#define MRB_NAN_BOXING
|
65
|
+
|
66
|
+
/* define on big endian machines; used by MRB_NAN_BOXING */
|
67
|
+
//#define MRB_ENDIAN_BIG
|
68
|
+
|
69
|
+
/* represent mrb_value as a word (natural unit of data for the processor) */
|
70
|
+
//#define MRB_WORD_BOXING
|
71
|
+
|
72
|
+
/* string class to handle UTF-8 encoding */
|
73
|
+
//#define MRB_UTF8_STRING
|
74
|
+
|
75
|
+
/* argv max size in mrb_funcall */
|
76
|
+
//#define MRB_FUNCALL_ARGC_MAX 16
|
77
|
+
|
78
|
+
/* number of object per heap page */
|
79
|
+
//#define MRB_HEAP_PAGE_SIZE 1024
|
80
|
+
|
81
|
+
/* if _etext and _edata available, mruby can reduce memory used by symbols */
|
82
|
+
//#define MRB_USE_ETEXT_EDATA
|
83
|
+
|
84
|
+
/* do not use __init_array_start to determine readonly data section;
|
85
|
+
effective only when MRB_USE_ETEXT_EDATA is defined */
|
86
|
+
//#define MRB_NO_INIT_ARRAY_START
|
87
|
+
|
88
|
+
/* turn off generational GC by default */
|
89
|
+
//#define MRB_GC_TURN_OFF_GENERATIONAL
|
90
|
+
|
91
|
+
/* default size of khash table bucket */
|
92
|
+
//#define KHASH_DEFAULT_SIZE 32
|
93
|
+
|
94
|
+
/* allocated memory address alignment */
|
95
|
+
//#define POOL_ALIGNMENT 4
|
96
|
+
|
97
|
+
/* page size of memory pool */
|
98
|
+
//#define POOL_PAGE_SIZE 16000
|
99
|
+
|
100
|
+
/* initial minimum size for string buffer */
|
101
|
+
//#define MRB_STR_BUF_MIN_SIZE 128
|
102
|
+
|
103
|
+
/* arena size */
|
104
|
+
//#define MRB_GC_ARENA_SIZE 100
|
105
|
+
|
106
|
+
/* fixed size GC arena */
|
107
|
+
//#define MRB_GC_FIXED_ARENA
|
108
|
+
|
109
|
+
/* state atexit stack size */
|
110
|
+
//#define MRB_FIXED_STATE_ATEXIT_STACK_SIZE 5
|
111
|
+
|
112
|
+
/* fixed size state atexit stack */
|
113
|
+
//#define MRB_FIXED_STATE_ATEXIT_STACK
|
114
|
+
|
115
|
+
/* -DMRB_DISABLE_XXXX to drop following features */
|
116
|
+
//#define MRB_DISABLE_STDIO /* use of stdio */
|
117
|
+
|
118
|
+
/* -DMRB_ENABLE_XXXX to enable following features */
|
119
|
+
//#define MRB_ENABLE_DEBUG_HOOK /* hooks for debugger */
|
120
|
+
|
121
|
+
/* end of configuration */
|
122
|
+
|
123
|
+
/* define MRB_DISABLE_XXXX from DISABLE_XXX (for compatibility) */
|
124
|
+
#ifdef DISABLE_STDIO
|
125
|
+
#define MRB_DISABLE_STDIO
|
126
|
+
#endif
|
127
|
+
|
128
|
+
/* define MRB_ENABLE_XXXX from ENABLE_XXX (for compatibility) */
|
129
|
+
#ifdef ENABLE_DEBUG
|
130
|
+
#define MRB_ENABLE_DEBUG_HOOK
|
131
|
+
#endif
|
132
|
+
|
133
|
+
#ifndef MRB_DISABLE_STDIO
|
134
|
+
# include <stdio.h>
|
135
|
+
#endif
|
136
|
+
|
137
|
+
#ifndef FALSE
|
138
|
+
# define FALSE 0
|
139
|
+
#endif
|
140
|
+
|
141
|
+
#ifndef TRUE
|
142
|
+
# define TRUE 1
|
143
|
+
#endif
|
144
|
+
|
145
|
+
#endif /* MRUBYCONF_H */
|
@@ -0,0 +1,1279 @@
|
|
1
|
+
/*
|
2
|
+
** mruby - An embeddable Ruby implementation
|
3
|
+
**
|
4
|
+
** Copyright (c) mruby developers 2010-2017
|
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: http://www.opensource.org/licenses/mit-license.php ]
|
26
|
+
*/
|
27
|
+
|
28
|
+
#ifndef MRUBY_H
|
29
|
+
#define MRUBY_H
|
30
|
+
|
31
|
+
#ifdef __cplusplus
|
32
|
+
#define __STDC_LIMIT_MACROS
|
33
|
+
#define __STDC_CONSTANT_MACROS
|
34
|
+
#define __STDC_FORMAT_MACROS
|
35
|
+
#endif
|
36
|
+
|
37
|
+
#include <stdint.h>
|
38
|
+
#include <stddef.h>
|
39
|
+
#include <limits.h>
|
40
|
+
|
41
|
+
#ifdef __cplusplus
|
42
|
+
#ifndef SIZE_MAX
|
43
|
+
#ifdef __SIZE_MAX__
|
44
|
+
#define SIZE_MAX __SIZE_MAX__
|
45
|
+
#else
|
46
|
+
#define SIZE_MAX std::numeric_limits<size_t>::max()
|
47
|
+
#endif
|
48
|
+
#endif
|
49
|
+
#endif
|
50
|
+
|
51
|
+
#ifdef MRB_DEBUG
|
52
|
+
#include <assert.h>
|
53
|
+
#define mrb_assert(p) assert(p)
|
54
|
+
#define mrb_assert_int_fit(t1,n,t2,max) assert((n)>=0 && ((sizeof(n)<=sizeof(t2))||(n<=(t1)(max))))
|
55
|
+
#else
|
56
|
+
#define mrb_assert(p) ((void)0)
|
57
|
+
#define mrb_assert_int_fit(t1,n,t2,max) ((void)0)
|
58
|
+
#endif
|
59
|
+
|
60
|
+
#if __STDC_VERSION__ >= 201112L
|
61
|
+
#define mrb_static_assert(exp, str) _Static_assert(exp, str)
|
62
|
+
#else
|
63
|
+
#define mrb_static_assert(exp, str) mrb_assert(exp)
|
64
|
+
#endif
|
65
|
+
|
66
|
+
#include "mrbconf.h"
|
67
|
+
|
68
|
+
#ifndef MRB_WITHOUT_FLOAT
|
69
|
+
#ifndef FLT_EPSILON
|
70
|
+
#define FLT_EPSILON (1.19209290e-07f)
|
71
|
+
#endif
|
72
|
+
#ifndef DBL_EPSILON
|
73
|
+
#define DBL_EPSILON ((double)2.22044604925031308085e-16L)
|
74
|
+
#endif
|
75
|
+
#ifndef LDBL_EPSILON
|
76
|
+
#define LDBL_EPSILON (1.08420217248550443401e-19L)
|
77
|
+
#endif
|
78
|
+
|
79
|
+
#ifdef MRB_USE_FLOAT
|
80
|
+
#define MRB_FLOAT_EPSILON FLT_EPSILON
|
81
|
+
#else
|
82
|
+
#define MRB_FLOAT_EPSILON DBL_EPSILON
|
83
|
+
#endif
|
84
|
+
#endif
|
85
|
+
|
86
|
+
#include "mruby/common.h"
|
87
|
+
#include <mruby/value.h>
|
88
|
+
#include <mruby/gc.h>
|
89
|
+
#include <mruby/version.h>
|
90
|
+
|
91
|
+
/**
|
92
|
+
* MRuby C API entry point
|
93
|
+
*/
|
94
|
+
MRB_BEGIN_DECL
|
95
|
+
|
96
|
+
typedef uint32_t mrb_code;
|
97
|
+
|
98
|
+
/**
|
99
|
+
* Required arguments signature type.
|
100
|
+
*/
|
101
|
+
typedef uint32_t mrb_aspec;
|
102
|
+
|
103
|
+
|
104
|
+
struct mrb_irep;
|
105
|
+
struct mrb_state;
|
106
|
+
|
107
|
+
/**
|
108
|
+
* Function pointer type of custom allocator used in @see mrb_open_allocf.
|
109
|
+
*
|
110
|
+
* The function pointing it must behave similarly as realloc except:
|
111
|
+
* - If ptr is NULL it must allocate new space.
|
112
|
+
* - If s is NULL, ptr must be freed.
|
113
|
+
*
|
114
|
+
* See @see mrb_default_allocf for the default implementation.
|
115
|
+
*/
|
116
|
+
typedef void* (*mrb_allocf) (struct mrb_state *mrb, void*, size_t, void *ud);
|
117
|
+
|
118
|
+
#ifndef MRB_FIXED_STATE_ATEXIT_STACK_SIZE
|
119
|
+
#define MRB_FIXED_STATE_ATEXIT_STACK_SIZE 5
|
120
|
+
#endif
|
121
|
+
|
122
|
+
typedef struct {
|
123
|
+
mrb_sym mid;
|
124
|
+
struct RProc *proc;
|
125
|
+
mrb_value *stackent;
|
126
|
+
int nregs;
|
127
|
+
int ridx;
|
128
|
+
int epos;
|
129
|
+
struct REnv *env;
|
130
|
+
mrb_code *pc; /* return address */
|
131
|
+
mrb_code *err; /* error position */
|
132
|
+
int argc;
|
133
|
+
int acc;
|
134
|
+
struct RClass *target_class;
|
135
|
+
} mrb_callinfo;
|
136
|
+
|
137
|
+
enum mrb_fiber_state {
|
138
|
+
MRB_FIBER_CREATED = 0,
|
139
|
+
MRB_FIBER_RUNNING,
|
140
|
+
MRB_FIBER_RESUMED,
|
141
|
+
MRB_FIBER_SUSPENDED,
|
142
|
+
MRB_FIBER_TRANSFERRED,
|
143
|
+
MRB_FIBER_TERMINATED,
|
144
|
+
};
|
145
|
+
|
146
|
+
struct mrb_context {
|
147
|
+
struct mrb_context *prev;
|
148
|
+
|
149
|
+
mrb_value *stack; /* stack of virtual machine */
|
150
|
+
mrb_value *stbase, *stend;
|
151
|
+
|
152
|
+
mrb_callinfo *ci;
|
153
|
+
mrb_callinfo *cibase, *ciend;
|
154
|
+
|
155
|
+
mrb_code **rescue; /* exception handler stack */
|
156
|
+
int rsize;
|
157
|
+
struct RProc **ensure; /* ensure handler stack */
|
158
|
+
int esize, eidx;
|
159
|
+
|
160
|
+
enum mrb_fiber_state status;
|
161
|
+
mrb_bool vmexec;
|
162
|
+
struct RFiber *fib;
|
163
|
+
};
|
164
|
+
|
165
|
+
#ifdef MRB_METHOD_CACHE_SIZE
|
166
|
+
# define MRB_METHOD_CACHE
|
167
|
+
#else
|
168
|
+
/* default method cache size: 128 */
|
169
|
+
/* cache size needs to be power of 2 */
|
170
|
+
# define MRB_METHOD_CACHE_SIZE (1<<7)
|
171
|
+
#endif
|
172
|
+
|
173
|
+
typedef mrb_value (*mrb_func_t)(struct mrb_state *mrb, mrb_value);
|
174
|
+
|
175
|
+
#ifdef MRB_METHOD_TABLE_INLINE
|
176
|
+
typedef uintptr_t mrb_method_t;
|
177
|
+
#else
|
178
|
+
typedef struct {
|
179
|
+
mrb_bool func_p;
|
180
|
+
union {
|
181
|
+
struct RProc *proc;
|
182
|
+
mrb_func_t func;
|
183
|
+
};
|
184
|
+
} mrb_method_t;
|
185
|
+
#endif
|
186
|
+
|
187
|
+
#ifdef MRB_METHOD_CACHE
|
188
|
+
struct mrb_cache_entry {
|
189
|
+
struct RClass *c;
|
190
|
+
mrb_sym mid;
|
191
|
+
mrb_method_t m;
|
192
|
+
};
|
193
|
+
#endif
|
194
|
+
|
195
|
+
struct mrb_jmpbuf;
|
196
|
+
|
197
|
+
typedef void (*mrb_atexit_func)(struct mrb_state*);
|
198
|
+
|
199
|
+
#define MRB_STATE_NO_REGEXP 1
|
200
|
+
#define MRB_STATE_REGEXP 2
|
201
|
+
|
202
|
+
typedef struct mrb_state {
|
203
|
+
struct mrb_jmpbuf *jmp;
|
204
|
+
|
205
|
+
uint32_t flags;
|
206
|
+
mrb_allocf allocf; /* memory allocation function */
|
207
|
+
void *allocf_ud; /* auxiliary data of allocf */
|
208
|
+
|
209
|
+
struct mrb_context *c;
|
210
|
+
struct mrb_context *root_c;
|
211
|
+
struct iv_tbl *globals; /* global variable table */
|
212
|
+
|
213
|
+
struct RObject *exc; /* exception */
|
214
|
+
|
215
|
+
struct RObject *top_self;
|
216
|
+
struct RClass *object_class; /* Object class */
|
217
|
+
struct RClass *class_class;
|
218
|
+
struct RClass *module_class;
|
219
|
+
struct RClass *proc_class;
|
220
|
+
struct RClass *string_class;
|
221
|
+
struct RClass *array_class;
|
222
|
+
struct RClass *hash_class;
|
223
|
+
struct RClass *range_class;
|
224
|
+
|
225
|
+
#ifndef MRB_WITHOUT_FLOAT
|
226
|
+
struct RClass *float_class;
|
227
|
+
#endif
|
228
|
+
struct RClass *fixnum_class;
|
229
|
+
struct RClass *true_class;
|
230
|
+
struct RClass *false_class;
|
231
|
+
struct RClass *nil_class;
|
232
|
+
struct RClass *symbol_class;
|
233
|
+
struct RClass *kernel_module;
|
234
|
+
|
235
|
+
struct alloca_header *mems;
|
236
|
+
mrb_gc gc;
|
237
|
+
|
238
|
+
#ifdef MRB_METHOD_CACHE
|
239
|
+
struct mrb_cache_entry cache[MRB_METHOD_CACHE_SIZE];
|
240
|
+
#endif
|
241
|
+
|
242
|
+
mrb_sym symidx;
|
243
|
+
struct kh_n2s *name2sym; /* symbol hash */
|
244
|
+
struct symbol_name *symtbl; /* symbol table */
|
245
|
+
size_t symcapa;
|
246
|
+
|
247
|
+
#ifdef MRB_ENABLE_DEBUG_HOOK
|
248
|
+
void (*code_fetch_hook)(struct mrb_state* mrb, struct mrb_irep *irep, mrb_code *pc, mrb_value *regs);
|
249
|
+
void (*debug_op_hook)(struct mrb_state* mrb, struct mrb_irep *irep, mrb_code *pc, mrb_value *regs);
|
250
|
+
#endif
|
251
|
+
|
252
|
+
#ifdef MRB_BYTECODE_DECODE_OPTION
|
253
|
+
mrb_code (*bytecode_decoder)(struct mrb_state* mrb, mrb_code code);
|
254
|
+
#endif
|
255
|
+
|
256
|
+
struct RClass *eException_class;
|
257
|
+
struct RClass *eStandardError_class;
|
258
|
+
struct RObject *nomem_err; /* pre-allocated NoMemoryError */
|
259
|
+
struct RObject *stack_err; /* pre-allocated SysStackError */
|
260
|
+
#ifdef MRB_GC_FIXED_ARENA
|
261
|
+
struct RObject *arena_err; /* pre-allocated arena overfow error */
|
262
|
+
#endif
|
263
|
+
|
264
|
+
void *ud; /* auxiliary data */
|
265
|
+
|
266
|
+
#ifdef MRB_FIXED_STATE_ATEXIT_STACK
|
267
|
+
mrb_atexit_func atexit_stack[MRB_FIXED_STATE_ATEXIT_STACK_SIZE];
|
268
|
+
#else
|
269
|
+
mrb_atexit_func *atexit_stack;
|
270
|
+
#endif
|
271
|
+
mrb_int atexit_stack_len;
|
272
|
+
} mrb_state;
|
273
|
+
|
274
|
+
/**
|
275
|
+
* Defines a new class.
|
276
|
+
*
|
277
|
+
* If you're creating a gem it may look something like this:
|
278
|
+
*
|
279
|
+
* !!!c
|
280
|
+
* void mrb_example_gem_init(mrb_state* mrb) {
|
281
|
+
* struct RClass *example_class;
|
282
|
+
* example_class = mrb_define_class(mrb, "Example_Class", mrb->object_class);
|
283
|
+
* }
|
284
|
+
*
|
285
|
+
* void mrb_example_gem_final(mrb_state* mrb) {
|
286
|
+
* //free(TheAnimals);
|
287
|
+
* }
|
288
|
+
*
|
289
|
+
* @param [mrb_state *] mrb The current mruby state.
|
290
|
+
* @param [const char *] name The name of the defined class.
|
291
|
+
* @param [struct RClass *] super The new class parent.
|
292
|
+
* @return [struct RClass *] Reference to the newly defined class.
|
293
|
+
* @see mrb_define_class_under
|
294
|
+
*/
|
295
|
+
MRB_API struct RClass *mrb_define_class(mrb_state *mrb, const char *name, struct RClass *super);
|
296
|
+
|
297
|
+
/**
|
298
|
+
* Defines a new module.
|
299
|
+
*
|
300
|
+
* @param [mrb_state *] mrb_state* The current mruby state.
|
301
|
+
* @param [const char *] char* The name of the module.
|
302
|
+
* @return [struct RClass *] Reference to the newly defined module.
|
303
|
+
*/
|
304
|
+
MRB_API struct RClass *mrb_define_module(mrb_state *, const char*);
|
305
|
+
MRB_API mrb_value mrb_singleton_class(mrb_state*, mrb_value);
|
306
|
+
|
307
|
+
/**
|
308
|
+
* Include a module in another class or module.
|
309
|
+
* Equivalent to:
|
310
|
+
*
|
311
|
+
* module B
|
312
|
+
* include A
|
313
|
+
* end
|
314
|
+
* @param [mrb_state *] mrb_state* The current mruby state.
|
315
|
+
* @param [struct RClass *] RClass* A reference to module or a class.
|
316
|
+
* @param [struct RClass *] RClass* A reference to the module to be included.
|
317
|
+
*/
|
318
|
+
MRB_API void mrb_include_module(mrb_state*, struct RClass*, struct RClass*);
|
319
|
+
|
320
|
+
/**
|
321
|
+
* Prepends a module in another class or module.
|
322
|
+
*
|
323
|
+
* Equivalent to:
|
324
|
+
* module B
|
325
|
+
* prepend A
|
326
|
+
* end
|
327
|
+
* @param [mrb_state *] mrb_state* The current mruby state.
|
328
|
+
* @param [struct RClass *] RClass* A reference to module or a class.
|
329
|
+
* @param [struct RClass *] RClass* A reference to the module to be prepended.
|
330
|
+
*/
|
331
|
+
MRB_API void mrb_prepend_module(mrb_state*, struct RClass*, struct RClass*);
|
332
|
+
|
333
|
+
/**
|
334
|
+
* Defines a global function in ruby.
|
335
|
+
*
|
336
|
+
* If you're creating a gem it may look something like this
|
337
|
+
*
|
338
|
+
* Example:
|
339
|
+
*
|
340
|
+
* !!!c
|
341
|
+
* mrb_value example_method(mrb_state* mrb, mrb_value self)
|
342
|
+
* {
|
343
|
+
* puts("Executing example command!");
|
344
|
+
* return self;
|
345
|
+
* }
|
346
|
+
*
|
347
|
+
* void mrb_example_gem_init(mrb_state* mrb)
|
348
|
+
* {
|
349
|
+
* mrb_define_method(mrb, mrb->kernel_module, "example_method", example_method, MRB_ARGS_NONE());
|
350
|
+
* }
|
351
|
+
*
|
352
|
+
* @param [mrb_state *] mrb The MRuby state reference.
|
353
|
+
* @param [struct RClass *] cla The class pointer where the method will be defined.
|
354
|
+
* @param [const char *] name The name of the method being defined.
|
355
|
+
* @param [mrb_func_t] func The function pointer to the method definition.
|
356
|
+
* @param [mrb_aspec] aspec The method parameters declaration.
|
357
|
+
*/
|
358
|
+
MRB_API void mrb_define_method(mrb_state *mrb, struct RClass *cla, const char *name, mrb_func_t func, mrb_aspec aspec);
|
359
|
+
|
360
|
+
/**
|
361
|
+
* Defines a class method.
|
362
|
+
*
|
363
|
+
* Example:
|
364
|
+
*
|
365
|
+
* # Ruby style
|
366
|
+
* class Foo
|
367
|
+
* def Foo.bar
|
368
|
+
* end
|
369
|
+
* end
|
370
|
+
* // C style
|
371
|
+
* mrb_value bar_method(mrb_state* mrb, mrb_value self){
|
372
|
+
* return mrb_nil_value();
|
373
|
+
* }
|
374
|
+
* void mrb_example_gem_init(mrb_state* mrb){
|
375
|
+
* struct RClass *foo;
|
376
|
+
* foo = mrb_define_class(mrb, "Foo", mrb->object_class);
|
377
|
+
* mrb_define_class_method(mrb, foo, "bar", bar_method, MRB_ARGS_NONE());
|
378
|
+
* }
|
379
|
+
* @param [mrb_state *] mrb_state* The MRuby state reference.
|
380
|
+
* @param [struct RClass *] RClass* The class where the class method will be defined.
|
381
|
+
* @param [const char *] char* The name of the class method being defined.
|
382
|
+
* @param [mrb_func_t] mrb_func_t The function pointer to the class method definition.
|
383
|
+
* @param [mrb_aspec] mrb_aspec The method parameters declaration.
|
384
|
+
*/
|
385
|
+
MRB_API void mrb_define_class_method(mrb_state *, struct RClass *, const char *, mrb_func_t, mrb_aspec);
|
386
|
+
MRB_API void mrb_define_singleton_method(mrb_state*, struct RObject*, const char*, mrb_func_t, mrb_aspec);
|
387
|
+
|
388
|
+
/**
|
389
|
+
* Defines a module fuction.
|
390
|
+
*
|
391
|
+
* Example:
|
392
|
+
*
|
393
|
+
* # Ruby style
|
394
|
+
* module Foo
|
395
|
+
* def Foo.bar
|
396
|
+
* end
|
397
|
+
* end
|
398
|
+
* // C style
|
399
|
+
* mrb_value bar_method(mrb_state* mrb, mrb_value self){
|
400
|
+
* return mrb_nil_value();
|
401
|
+
* }
|
402
|
+
* void mrb_example_gem_init(mrb_state* mrb){
|
403
|
+
* struct RClass *foo;
|
404
|
+
* foo = mrb_define_module(mrb, "Foo");
|
405
|
+
* mrb_define_module_function(mrb, foo, "bar", bar_method, MRB_ARGS_NONE());
|
406
|
+
* }
|
407
|
+
* @param [mrb_state *] mrb_state* The MRuby state reference.
|
408
|
+
* @param [struct RClass *] RClass* The module where the module function will be defined.
|
409
|
+
* @param [const char *] char* The name of the module function being defined.
|
410
|
+
* @param [mrb_func_t] mrb_func_t The function pointer to the module function definition.
|
411
|
+
* @param [mrb_aspec] mrb_aspec The method parameters declaration.
|
412
|
+
*/
|
413
|
+
MRB_API void mrb_define_module_function(mrb_state*, struct RClass*, const char*, mrb_func_t, mrb_aspec);
|
414
|
+
|
415
|
+
/**
|
416
|
+
* Defines a constant.
|
417
|
+
*
|
418
|
+
* Example:
|
419
|
+
*
|
420
|
+
* # Ruby style
|
421
|
+
* class ExampleClass
|
422
|
+
* AGE = 22
|
423
|
+
* end
|
424
|
+
* // C style
|
425
|
+
* #include <stdio.h>
|
426
|
+
* #include <mruby.h>
|
427
|
+
*
|
428
|
+
* void
|
429
|
+
* mrb_example_gem_init(mrb_state* mrb){
|
430
|
+
* mrb_define_const(mrb, mrb->kernel_module, "AGE", mrb_fixnum_value(22));
|
431
|
+
* }
|
432
|
+
*
|
433
|
+
* mrb_value
|
434
|
+
* mrb_example_gem_final(mrb_state* mrb){
|
435
|
+
* }
|
436
|
+
* @param [mrb_state *] mrb_state* The MRuby state reference.
|
437
|
+
* @param [struct RClass *] RClass* A class or module the constant is defined in.
|
438
|
+
* @param [const char *] name The name of the constant being defined.
|
439
|
+
* @param [mrb_value] mrb_value The value for the constant.
|
440
|
+
*/
|
441
|
+
MRB_API void mrb_define_const(mrb_state*, struct RClass*, const char *name, mrb_value);
|
442
|
+
|
443
|
+
/**
|
444
|
+
* Undefines a method.
|
445
|
+
*
|
446
|
+
* Example:
|
447
|
+
*
|
448
|
+
* # Ruby style
|
449
|
+
*
|
450
|
+
* class ExampleClassA
|
451
|
+
* def example_method
|
452
|
+
* "example"
|
453
|
+
* end
|
454
|
+
* end
|
455
|
+
* ExampleClassA.new.example_method # => example
|
456
|
+
*
|
457
|
+
* class ExampleClassB < ExampleClassA
|
458
|
+
* undef_method :example_method
|
459
|
+
* end
|
460
|
+
*
|
461
|
+
* ExampleClassB.new.example_method # => undefined method 'example_method' for ExampleClassB (NoMethodError)
|
462
|
+
*
|
463
|
+
* // C style
|
464
|
+
* #include <stdio.h>
|
465
|
+
* #include <mruby.h>
|
466
|
+
*
|
467
|
+
* mrb_value
|
468
|
+
* mrb_example_method(mrb_state *mrb){
|
469
|
+
* return mrb_str_new_lit(mrb, "example");
|
470
|
+
* }
|
471
|
+
*
|
472
|
+
* void
|
473
|
+
* mrb_example_gem_init(mrb_state* mrb){
|
474
|
+
* struct RClass *example_class_a;
|
475
|
+
* struct RClass *example_class_b;
|
476
|
+
* struct RClass *example_class_c;
|
477
|
+
*
|
478
|
+
* example_class_a = mrb_define_class(mrb, "ExampleClassA", mrb->object_class);
|
479
|
+
* mrb_define_method(mrb, example_class_a, "example_method", mrb_example_method, MRB_ARGS_NONE());
|
480
|
+
* example_class_b = mrb_define_class(mrb, "ExampleClassB", example_class_a);
|
481
|
+
* example_class_c = mrb_define_class(mrb, "ExampleClassC", example_class_b);
|
482
|
+
* mrb_undef_method(mrb, example_class_c, "example_method");
|
483
|
+
* }
|
484
|
+
*
|
485
|
+
* mrb_example_gem_final(mrb_state* mrb){
|
486
|
+
* }
|
487
|
+
* @param [mrb_state*] mrb_state* The mruby state reference.
|
488
|
+
* @param [struct RClass*] RClass* A class the method will be undefined from.
|
489
|
+
* @param [const char*] constchar* The name of the method to be undefined.
|
490
|
+
*/
|
491
|
+
MRB_API void mrb_undef_method(mrb_state*, struct RClass*, const char*);
|
492
|
+
|
493
|
+
/**
|
494
|
+
* Undefine a class method.
|
495
|
+
* Example:
|
496
|
+
*
|
497
|
+
* # Ruby style
|
498
|
+
* class ExampleClass
|
499
|
+
* def self.example_method
|
500
|
+
* "example"
|
501
|
+
* end
|
502
|
+
* end
|
503
|
+
*
|
504
|
+
* ExampleClass.example_method
|
505
|
+
*
|
506
|
+
* // C style
|
507
|
+
* #include <stdio.h>
|
508
|
+
* #include <mruby.h>
|
509
|
+
*
|
510
|
+
* mrb_value
|
511
|
+
* mrb_example_method(mrb_state *mrb){
|
512
|
+
* return mrb_str_new_lit(mrb, "example");
|
513
|
+
* }
|
514
|
+
*
|
515
|
+
* void
|
516
|
+
* mrb_example_gem_init(mrb_state* mrb){
|
517
|
+
* struct RClass *example_class;
|
518
|
+
* example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class);
|
519
|
+
* mrb_define_class_method(mrb, example_class, "example_method", mrb_example_method, MRB_ARGS_NONE());
|
520
|
+
* mrb_undef_class_method(mrb, example_class, "example_method");
|
521
|
+
* }
|
522
|
+
*
|
523
|
+
* void
|
524
|
+
* mrb_example_gem_final(mrb_state* mrb){
|
525
|
+
* }
|
526
|
+
* @param [mrb_state*] mrb_state* The mruby state reference.
|
527
|
+
* @param [RClass*] RClass* A class the class method will be undefined from.
|
528
|
+
* @param [constchar*] constchar* The name of the class method to be undefined.
|
529
|
+
*/
|
530
|
+
MRB_API void mrb_undef_class_method(mrb_state*, struct RClass*, const char*);
|
531
|
+
|
532
|
+
/**
|
533
|
+
* Initialize a new object instace of c class.
|
534
|
+
*
|
535
|
+
* Example:
|
536
|
+
*
|
537
|
+
* # Ruby style
|
538
|
+
* class ExampleClass
|
539
|
+
* end
|
540
|
+
*
|
541
|
+
* p ExampleClass # => #<ExampleClass:0x9958588>
|
542
|
+
* // C style
|
543
|
+
* #include <stdio.h>
|
544
|
+
* #include <mruby.h>
|
545
|
+
*
|
546
|
+
* void
|
547
|
+
* mrb_example_gem_init(mrb_state* mrb) {
|
548
|
+
* struct RClass *example_class;
|
549
|
+
* mrb_value obj;
|
550
|
+
* example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class); # => class ExampleClass; end
|
551
|
+
* obj = mrb_obj_new(mrb, example_class, 0, NULL); # => ExampleClass.new
|
552
|
+
* mrb_p(mrb, obj); // => Kernel#p
|
553
|
+
* }
|
554
|
+
* @param [mrb_state*] mrb The current mruby state.
|
555
|
+
* @param [RClass*] c Reference to the class of the new object.
|
556
|
+
* @param [mrb_int] argc Number of arguments in argv
|
557
|
+
* @param [const mrb_value *] argv Array of mrb_value to initialize the object
|
558
|
+
* @return [mrb_value] The newly initialized object
|
559
|
+
*/
|
560
|
+
MRB_API mrb_value mrb_obj_new(mrb_state *mrb, struct RClass *c, mrb_int argc, const mrb_value *argv);
|
561
|
+
|
562
|
+
/** @see mrb_obj_new */
|
563
|
+
MRB_INLINE mrb_value mrb_class_new_instance(mrb_state *mrb, mrb_int argc, const mrb_value *argv, struct RClass *c)
|
564
|
+
{
|
565
|
+
return mrb_obj_new(mrb,c,argc,argv);
|
566
|
+
}
|
567
|
+
|
568
|
+
MRB_API mrb_value mrb_instance_new(mrb_state *mrb, mrb_value cv);
|
569
|
+
|
570
|
+
/**
|
571
|
+
* Creates a new instance of Class, Class.
|
572
|
+
*
|
573
|
+
* Example:
|
574
|
+
*
|
575
|
+
* void
|
576
|
+
* mrb_example_gem_init(mrb_state* mrb) {
|
577
|
+
* struct RClass *example_class;
|
578
|
+
*
|
579
|
+
* mrb_value obj;
|
580
|
+
* example_class = mrb_class_new(mrb, mrb->object_class);
|
581
|
+
* obj = mrb_obj_new(mrb, example_class, 0, NULL); // => #<#<Class:0x9a945b8>:0x9a94588>
|
582
|
+
* mrb_p(mrb, obj); // => Kernel#p
|
583
|
+
* }
|
584
|
+
*
|
585
|
+
* @param [mrb_state*] mrb The current mruby state.
|
586
|
+
* @param [struct RClass *] super The super class or parent.
|
587
|
+
* @return [struct RClass *] Reference to the new class.
|
588
|
+
*/
|
589
|
+
MRB_API struct RClass * mrb_class_new(mrb_state *mrb, struct RClass *super);
|
590
|
+
|
591
|
+
/**
|
592
|
+
* Creates a new module, Module.
|
593
|
+
*
|
594
|
+
* Example:
|
595
|
+
* void
|
596
|
+
* mrb_example_gem_init(mrb_state* mrb) {
|
597
|
+
* struct RClass *example_module;
|
598
|
+
*
|
599
|
+
* example_module = mrb_module_new(mrb);
|
600
|
+
* }
|
601
|
+
*
|
602
|
+
* @param [mrb_state*] mrb The current mruby state.
|
603
|
+
* @return [struct RClass *] Reference to the new module.
|
604
|
+
*/
|
605
|
+
MRB_API struct RClass * mrb_module_new(mrb_state *mrb);
|
606
|
+
|
607
|
+
/**
|
608
|
+
* Returns an mrb_bool. True if class was defined, and false if the class was not defined.
|
609
|
+
*
|
610
|
+
* Example:
|
611
|
+
* void
|
612
|
+
* mrb_example_gem_init(mrb_state* mrb) {
|
613
|
+
* struct RClass *example_class;
|
614
|
+
* mrb_bool cd;
|
615
|
+
*
|
616
|
+
* example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class);
|
617
|
+
* cd = mrb_class_defined(mrb, "ExampleClass");
|
618
|
+
*
|
619
|
+
* // If mrb_class_defined returns 1 then puts "True"
|
620
|
+
* // If mrb_class_defined returns 0 then puts "False"
|
621
|
+
* if (cd == 1){
|
622
|
+
* puts("True");
|
623
|
+
* }
|
624
|
+
* else {
|
625
|
+
* puts("False");
|
626
|
+
* }
|
627
|
+
* }
|
628
|
+
*
|
629
|
+
* @param [mrb_state*] mrb The current mruby state.
|
630
|
+
* @param [const char *] name A string representing the name of the class.
|
631
|
+
* @return [mrb_bool] A boolean value.
|
632
|
+
*/
|
633
|
+
MRB_API mrb_bool mrb_class_defined(mrb_state *mrb, const char *name);
|
634
|
+
|
635
|
+
/**
|
636
|
+
* Gets a class.
|
637
|
+
* @param [mrb_state*] mrb The current mruby state.
|
638
|
+
* @param [const char *] name The name of the class.
|
639
|
+
* @return [struct RClass *] A reference to the class.
|
640
|
+
*/
|
641
|
+
MRB_API struct RClass * mrb_class_get(mrb_state *mrb, const char *name);
|
642
|
+
|
643
|
+
/**
|
644
|
+
* Gets a exception class.
|
645
|
+
* @param [mrb_state*] mrb The current mruby state.
|
646
|
+
* @param [const char *] name The name of the class.
|
647
|
+
* @return [struct RClass *] A reference to the class.
|
648
|
+
*/
|
649
|
+
MRB_API struct RClass * mrb_exc_get(mrb_state *mrb, const char *name);
|
650
|
+
|
651
|
+
/**
|
652
|
+
* Returns an mrb_bool. True if inner class was defined, and false if the inner class was not defined.
|
653
|
+
*
|
654
|
+
* Example:
|
655
|
+
* void
|
656
|
+
* mrb_example_gem_init(mrb_state* mrb) {
|
657
|
+
* struct RClass *example_outer, *example_inner;
|
658
|
+
* mrb_bool cd;
|
659
|
+
*
|
660
|
+
* example_outer = mrb_define_module(mrb, "ExampleOuter");
|
661
|
+
*
|
662
|
+
* example_inner = mrb_define_class_under(mrb, example_outer, "ExampleInner", mrb->object_class);
|
663
|
+
* cd = mrb_class_defined_under(mrb, example_outer, "ExampleInner");
|
664
|
+
*
|
665
|
+
* // If mrb_class_defined_under returns 1 then puts "True"
|
666
|
+
* // If mrb_class_defined_under returns 0 then puts "False"
|
667
|
+
* if (cd == 1){
|
668
|
+
* puts("True");
|
669
|
+
* }
|
670
|
+
* else {
|
671
|
+
* puts("False");
|
672
|
+
* }
|
673
|
+
* }
|
674
|
+
*
|
675
|
+
* @param [mrb_state*] mrb The current mruby state.
|
676
|
+
* @param [struct RClass *] outer The name of the outer class.
|
677
|
+
* @param [const char *] name A string representing the name of the inner class.
|
678
|
+
* @return [mrb_bool] A boolean value.
|
679
|
+
*/
|
680
|
+
MRB_API mrb_bool mrb_class_defined_under(mrb_state *mrb, struct RClass *outer, const char *name);
|
681
|
+
|
682
|
+
/**
|
683
|
+
* Gets a child class.
|
684
|
+
* @param [mrb_state*] mrb The current mruby state.
|
685
|
+
* @param [struct RClass *] outer The name of the parent class.
|
686
|
+
* @param [const char *] name The name of the class.
|
687
|
+
* @return [struct RClass *] A reference to the class.
|
688
|
+
*/
|
689
|
+
MRB_API struct RClass * mrb_class_get_under(mrb_state *mrb, struct RClass *outer, const char *name);
|
690
|
+
|
691
|
+
/**
|
692
|
+
* Gets a module.
|
693
|
+
* @param [mrb_state*] mrb The current mruby state.
|
694
|
+
* @param [const char *] name The name of the module.
|
695
|
+
* @return [struct RClass *] A reference to the module.
|
696
|
+
*/
|
697
|
+
MRB_API struct RClass * mrb_module_get(mrb_state *mrb, const char *name);
|
698
|
+
|
699
|
+
/**
|
700
|
+
* Gets a module defined under another module.
|
701
|
+
* @param [mrb_state*] mrb The current mruby state.
|
702
|
+
* @param [struct RClass *] outer The name of the outer module.
|
703
|
+
* @param [const char *] name The name of the module.
|
704
|
+
* @return [struct RClass *] A reference to the module.
|
705
|
+
*/
|
706
|
+
MRB_API struct RClass * mrb_module_get_under(mrb_state *mrb, struct RClass *outer, const char *name);
|
707
|
+
MRB_API mrb_value mrb_notimplement_m(mrb_state*, mrb_value);
|
708
|
+
|
709
|
+
/**
|
710
|
+
* Duplicate an object.
|
711
|
+
*
|
712
|
+
* Equivalent to:
|
713
|
+
* Object#dup
|
714
|
+
* @param [mrb_state*] mrb The current mruby state.
|
715
|
+
* @param [mrb_value] obj Object to be duplicate.
|
716
|
+
* @return [mrb_value] The newly duplicated object.
|
717
|
+
*/
|
718
|
+
MRB_API mrb_value mrb_obj_dup(mrb_state *mrb, mrb_value obj);
|
719
|
+
MRB_API mrb_value mrb_check_to_integer(mrb_state *mrb, mrb_value val, const char *method);
|
720
|
+
|
721
|
+
/**
|
722
|
+
* Returns true if obj responds to the given method. If the method was defined for that
|
723
|
+
* class it returns true, it returns false otherwise.
|
724
|
+
*
|
725
|
+
* Example:
|
726
|
+
* # Ruby style
|
727
|
+
* class ExampleClass
|
728
|
+
* def example_method
|
729
|
+
* end
|
730
|
+
* end
|
731
|
+
*
|
732
|
+
* ExampleClass.new.respond_to?(:example_method) # => true
|
733
|
+
*
|
734
|
+
* // C style
|
735
|
+
* void
|
736
|
+
* mrb_example_gem_init(mrb_state* mrb) {
|
737
|
+
* struct RClass *example_class;
|
738
|
+
* mrb_sym mid;
|
739
|
+
* mrb_bool obj_resp;
|
740
|
+
*
|
741
|
+
* example_class = mrb_define_class(mrb, "ExampleClass", mrb->object_class);
|
742
|
+
* mrb_define_method(mrb, example_class, "example_method", exampleMethod, MRB_ARGS_NONE());
|
743
|
+
* mid = mrb_intern_str(mrb, mrb_str_new_lit(mrb, "example_method" ));
|
744
|
+
* obj_resp = mrb_obj_respond_to(mrb, example_class, mid); // => 1(true in Ruby world)
|
745
|
+
*
|
746
|
+
* // If mrb_obj_respond_to returns 1 then puts "True"
|
747
|
+
* // If mrb_obj_respond_to returns 0 then puts "False"
|
748
|
+
* if (obj_resp == 1) {
|
749
|
+
* puts("True");
|
750
|
+
* }
|
751
|
+
* else if (obj_resp == 0) {
|
752
|
+
* puts("False");
|
753
|
+
* }
|
754
|
+
* }
|
755
|
+
*
|
756
|
+
* @param [mrb_state*] mrb The current mruby state.
|
757
|
+
* @param [struct RClass *] c A reference to a class.
|
758
|
+
* @param [mrb_sym] mid A symbol referencing a method id.
|
759
|
+
* @return [mrb_bool] A boolean value.
|
760
|
+
*/
|
761
|
+
MRB_API mrb_bool mrb_obj_respond_to(mrb_state *mrb, struct RClass* c, mrb_sym mid);
|
762
|
+
|
763
|
+
/**
|
764
|
+
* Defines a new class under a given module
|
765
|
+
*
|
766
|
+
* @param [mrb_state*] mrb The current mruby state.
|
767
|
+
* @param [struct RClass *] outer Reference to the module under which the new class will be defined
|
768
|
+
* @param [const char *] name The name of the defined class
|
769
|
+
* @param [struct RClass *] super The new class parent
|
770
|
+
* @return [struct RClass *] Reference to the newly defined class
|
771
|
+
* @see mrb_define_class
|
772
|
+
*/
|
773
|
+
MRB_API struct RClass * mrb_define_class_under(mrb_state *mrb, struct RClass *outer, const char *name, struct RClass *super);
|
774
|
+
|
775
|
+
MRB_API struct RClass * mrb_define_module_under(mrb_state *mrb, struct RClass *outer, const char *name);
|
776
|
+
|
777
|
+
/**
|
778
|
+
* Function requires n arguments.
|
779
|
+
*
|
780
|
+
* @param n
|
781
|
+
* The number of required arguments.
|
782
|
+
*/
|
783
|
+
#define MRB_ARGS_REQ(n) ((mrb_aspec)((n)&0x1f) << 18)
|
784
|
+
|
785
|
+
/**
|
786
|
+
* Funtion takes n optional arguments
|
787
|
+
*
|
788
|
+
* @param n
|
789
|
+
* The number of optional arguments.
|
790
|
+
*/
|
791
|
+
#define MRB_ARGS_OPT(n) ((mrb_aspec)((n)&0x1f) << 13)
|
792
|
+
|
793
|
+
/**
|
794
|
+
* Funtion takes n1 mandatory arguments and n2 optional arguments
|
795
|
+
*
|
796
|
+
* @param n1
|
797
|
+
* The number of required arguments.
|
798
|
+
* @param n2
|
799
|
+
* The number of optional arguments.
|
800
|
+
*/
|
801
|
+
#define MRB_ARGS_ARG(n1,n2) (MRB_ARGS_REQ(n1)|MRB_ARGS_OPT(n2))
|
802
|
+
|
803
|
+
/** rest argument */
|
804
|
+
#define MRB_ARGS_REST() ((mrb_aspec)(1 << 12))
|
805
|
+
|
806
|
+
/** required arguments after rest */
|
807
|
+
#define MRB_ARGS_POST(n) ((mrb_aspec)((n)&0x1f) << 7)
|
808
|
+
|
809
|
+
/** keyword arguments (n of keys, kdict) */
|
810
|
+
#define MRB_ARGS_KEY(n1,n2) ((mrb_aspec)((((n1)&0x1f) << 2) | ((n2)?(1<<1):0)))
|
811
|
+
|
812
|
+
/**
|
813
|
+
* Function takes a block argument
|
814
|
+
*/
|
815
|
+
#define MRB_ARGS_BLOCK() ((mrb_aspec)1)
|
816
|
+
|
817
|
+
/**
|
818
|
+
* Function accepts any number of arguments
|
819
|
+
*/
|
820
|
+
#define MRB_ARGS_ANY() MRB_ARGS_REST()
|
821
|
+
|
822
|
+
/**
|
823
|
+
* Function accepts no arguments
|
824
|
+
*/
|
825
|
+
#define MRB_ARGS_NONE() ((mrb_aspec)0)
|
826
|
+
|
827
|
+
/**
|
828
|
+
* Format specifiers for {mrb_get_args} function
|
829
|
+
*
|
830
|
+
* Must be a C string composed of the following format specifiers:
|
831
|
+
*
|
832
|
+
* | char | Ruby type | C types | Notes |
|
833
|
+
* |:----:|----------------|-------------------|----------------------------------------------------|
|
834
|
+
* | `o` | {Object} | {mrb_value} | Could be used to retrieve any type of argument |
|
835
|
+
* | `C` | {Class}/{Module} | {mrb_value} | |
|
836
|
+
* | `S` | {String} | {mrb_value} | when `!` follows, the value may be `nil` |
|
837
|
+
* | `A` | {Array} | {mrb_value} | when `!` follows, the value may be `nil` |
|
838
|
+
* | `H` | {Hash} | {mrb_value} | when `!` follows, the value may be `nil` |
|
839
|
+
* | `s` | {String} | char *, {mrb_int} | Receive two arguments; `s!` gives (`NULL`,`0`) for `nil` |
|
840
|
+
* | `z` | {String} | char * | `NULL` terminated string; `z!` gives `NULL` for `nil` |
|
841
|
+
* | `a` | {Array} | {mrb_value} *, {mrb_int} | Receive two arguments; `a!` gives (`NULL`,`0`) for `nil` |
|
842
|
+
* | `f` | {Float} | {mrb_float} | |
|
843
|
+
* | `i` | {Integer} | {mrb_int} | |
|
844
|
+
* | `b` | boolean | {mrb_bool} | |
|
845
|
+
* | `n` | {Symbol} | {mrb_sym} | |
|
846
|
+
* | `&` | block | {mrb_value} | |
|
847
|
+
* | `*` | rest arguments | {mrb_value} *, {mrb_int} | Receive the rest of arguments as an array. |
|
848
|
+
* | | | optional | | After this spec following specs would be optional. |
|
849
|
+
* | `?` | optional given | {mrb_bool} | `TRUE` if preceding argument is given. Used to check optional argument is given. |
|
850
|
+
*
|
851
|
+
* @see mrb_get_args
|
852
|
+
*/
|
853
|
+
typedef const char *mrb_args_format;
|
854
|
+
|
855
|
+
/**
|
856
|
+
* Retrieve arguments from mrb_state.
|
857
|
+
*
|
858
|
+
* When applicable, implicit conversions (such as `to_str`, `to_ary`, `to_hash`) are
|
859
|
+
* applied to received arguments.
|
860
|
+
* Used inside a function of mrb_func_t type.
|
861
|
+
*
|
862
|
+
* @param mrb The current MRuby state.
|
863
|
+
* @param format [mrb_args_format] is a list of format specifiers
|
864
|
+
* @param ... The passing variadic arguments must be a pointer of retrieving type.
|
865
|
+
* @return the number of arguments retrieved.
|
866
|
+
* @see mrb_args_format
|
867
|
+
*/
|
868
|
+
MRB_API mrb_int mrb_get_args(mrb_state *mrb, mrb_args_format format, ...);
|
869
|
+
|
870
|
+
static inline mrb_sym
|
871
|
+
mrb_get_mid(mrb_state *mrb) /* get method symbol */
|
872
|
+
{
|
873
|
+
return mrb->c->ci->mid;
|
874
|
+
}
|
875
|
+
|
876
|
+
/**
|
877
|
+
* Retrieve number of arguments from mrb_state.
|
878
|
+
*
|
879
|
+
* Correctly handles *splat arguments.
|
880
|
+
*/
|
881
|
+
MRB_API mrb_int mrb_get_argc(mrb_state *mrb);
|
882
|
+
|
883
|
+
MRB_API mrb_value* mrb_get_argv(mrb_state *mrb);
|
884
|
+
|
885
|
+
/* `strlen` for character string literals (use with caution or `strlen` instead)
|
886
|
+
Adjacent string literals are concatenated in C/C++ in translation phase 6.
|
887
|
+
If `lit` is not one, the compiler will report a syntax error:
|
888
|
+
MSVC: "error C2143: syntax error : missing ')' before 'string'"
|
889
|
+
GCC: "error: expected ')' before string constant"
|
890
|
+
*/
|
891
|
+
#define mrb_strlen_lit(lit) (sizeof(lit "") - 1)
|
892
|
+
|
893
|
+
/**
|
894
|
+
* Call existing ruby functions.
|
895
|
+
*
|
896
|
+
* #include <stdio.h>
|
897
|
+
* #include <mruby.h>
|
898
|
+
* #include "mruby/compile.h"
|
899
|
+
*
|
900
|
+
* int
|
901
|
+
* main()
|
902
|
+
* {
|
903
|
+
* mrb_int i = 99;
|
904
|
+
* mrb_state *mrb = mrb_open();
|
905
|
+
*
|
906
|
+
* if (!mrb) { }
|
907
|
+
* FILE *fp = fopen("test.rb","r");
|
908
|
+
* mrb_value obj = mrb_load_file(mrb,fp);
|
909
|
+
* mrb_funcall(mrb, obj, "method_name", 1, mrb_fixnum_value(i));
|
910
|
+
* fclose(fp);
|
911
|
+
* mrb_close(mrb);
|
912
|
+
* }
|
913
|
+
* @param [mrb_state*] mrb_state* The current mruby state.
|
914
|
+
* @param [mrb_value] mrb_value A reference to an mruby value.
|
915
|
+
* @param [const char*] const char* The name of the method.
|
916
|
+
* @param [mrb_int] mrb_int The number of arguments the method has.
|
917
|
+
* @param [...] ... Variadic values(not type safe!).
|
918
|
+
* @return [mrb_value] mrb_value mruby function value.
|
919
|
+
*/
|
920
|
+
MRB_API mrb_value mrb_funcall(mrb_state*, mrb_value, const char*, mrb_int,...);
|
921
|
+
/**
|
922
|
+
* Call existing ruby functions. This is basically the type safe version of mrb_funcall.
|
923
|
+
*
|
924
|
+
* #include <stdio.h>
|
925
|
+
* #include <mruby.h>
|
926
|
+
* #include "mruby/compile.h"
|
927
|
+
* int
|
928
|
+
* main()
|
929
|
+
* {
|
930
|
+
* mrb_int i = 99;
|
931
|
+
* mrb_state *mrb = mrb_open();
|
932
|
+
*
|
933
|
+
* if (!mrb) { }
|
934
|
+
* mrb_sym m_sym = mrb_intern_lit(mrb, "method_name"); // Symbol for method.
|
935
|
+
*
|
936
|
+
* FILE *fp = fopen("test.rb","r");
|
937
|
+
* mrb_value obj = mrb_load_file(mrb,fp);
|
938
|
+
* mrb_funcall_argv(mrb, obj, m_sym, 1, &obj); // Calling ruby function from test.rb.
|
939
|
+
* fclose(fp);
|
940
|
+
* mrb_close(mrb);
|
941
|
+
* }
|
942
|
+
* @param [mrb_state*] mrb_state* The current mruby state.
|
943
|
+
* @param [mrb_value] mrb_value A reference to an mruby value.
|
944
|
+
* @param [mrb_sym] mrb_sym The symbol representing the method.
|
945
|
+
* @param [mrb_int] mrb_int The number of arguments the method has.
|
946
|
+
* @param [const mrb_value*] mrb_value* Pointer to the object.
|
947
|
+
* @return [mrb_value] mrb_value mruby function value.
|
948
|
+
* @see mrb_funcall
|
949
|
+
*/
|
950
|
+
MRB_API mrb_value mrb_funcall_argv(mrb_state*, mrb_value, mrb_sym, mrb_int, const mrb_value*);
|
951
|
+
/**
|
952
|
+
* Call existing ruby functions with a block.
|
953
|
+
*/
|
954
|
+
MRB_API mrb_value mrb_funcall_with_block(mrb_state*, mrb_value, mrb_sym, mrb_int, const mrb_value*, mrb_value);
|
955
|
+
/**
|
956
|
+
* Create a symbol
|
957
|
+
*
|
958
|
+
* # Ruby style:
|
959
|
+
* :pizza # => :pizza
|
960
|
+
*
|
961
|
+
* // C style:
|
962
|
+
* mrb_sym m_sym = mrb_intern_lit(mrb, "pizza"); // => :pizza
|
963
|
+
* @param [mrb_state*] mrb_state* The current mruby state.
|
964
|
+
* @param [const char*] const char* The name of the method.
|
965
|
+
* @return [mrb_sym] mrb_sym A symbol.
|
966
|
+
*/
|
967
|
+
MRB_API mrb_sym mrb_intern_cstr(mrb_state*,const char*);
|
968
|
+
MRB_API mrb_sym mrb_intern(mrb_state*,const char*,size_t);
|
969
|
+
MRB_API mrb_sym mrb_intern_static(mrb_state*,const char*,size_t);
|
970
|
+
#define mrb_intern_lit(mrb, lit) mrb_intern_static(mrb, lit, mrb_strlen_lit(lit))
|
971
|
+
MRB_API mrb_sym mrb_intern_str(mrb_state*,mrb_value);
|
972
|
+
MRB_API mrb_value mrb_check_intern_cstr(mrb_state*,const char*);
|
973
|
+
MRB_API mrb_value mrb_check_intern(mrb_state*,const char*,size_t);
|
974
|
+
MRB_API mrb_value mrb_check_intern_str(mrb_state*,mrb_value);
|
975
|
+
MRB_API const char *mrb_sym2name(mrb_state*,mrb_sym);
|
976
|
+
MRB_API const char *mrb_sym2name_len(mrb_state*,mrb_sym,mrb_int*);
|
977
|
+
MRB_API mrb_value mrb_sym2str(mrb_state*,mrb_sym);
|
978
|
+
|
979
|
+
MRB_API void *mrb_malloc(mrb_state*, size_t); /* raise RuntimeError if no mem */
|
980
|
+
MRB_API void *mrb_calloc(mrb_state*, size_t, size_t); /* ditto */
|
981
|
+
MRB_API void *mrb_realloc(mrb_state*, void*, size_t); /* ditto */
|
982
|
+
MRB_API void *mrb_realloc_simple(mrb_state*, void*, size_t); /* return NULL if no memory available */
|
983
|
+
MRB_API void *mrb_malloc_simple(mrb_state*, size_t); /* return NULL if no memory available */
|
984
|
+
MRB_API struct RBasic *mrb_obj_alloc(mrb_state*, enum mrb_vtype, struct RClass*);
|
985
|
+
MRB_API void mrb_free(mrb_state*, void*);
|
986
|
+
|
987
|
+
MRB_API mrb_value mrb_str_new(mrb_state *mrb, const char *p, size_t len);
|
988
|
+
|
989
|
+
/**
|
990
|
+
* Turns a C string into a Ruby string value.
|
991
|
+
*/
|
992
|
+
MRB_API mrb_value mrb_str_new_cstr(mrb_state*, const char*);
|
993
|
+
MRB_API mrb_value mrb_str_new_static(mrb_state *mrb, const char *p, size_t len);
|
994
|
+
#define mrb_str_new_lit(mrb, lit) mrb_str_new_static(mrb, (lit), mrb_strlen_lit(lit))
|
995
|
+
|
996
|
+
#ifdef _WIN32
|
997
|
+
char* mrb_utf8_from_locale(const char *p, int len);
|
998
|
+
char* mrb_locale_from_utf8(const char *p, int len);
|
999
|
+
#define mrb_locale_free(p) free(p)
|
1000
|
+
#define mrb_utf8_free(p) free(p)
|
1001
|
+
#else
|
1002
|
+
#define mrb_utf8_from_locale(p, l) (p)
|
1003
|
+
#define mrb_locale_from_utf8(p, l) (p)
|
1004
|
+
#define mrb_locale_free(p)
|
1005
|
+
#define mrb_utf8_free(p)
|
1006
|
+
#endif
|
1007
|
+
|
1008
|
+
/**
|
1009
|
+
* Creates new mrb_state.
|
1010
|
+
*
|
1011
|
+
* @return
|
1012
|
+
* Pointer to the newly created mrb_state.
|
1013
|
+
*/
|
1014
|
+
MRB_API mrb_state* mrb_open(void);
|
1015
|
+
|
1016
|
+
/**
|
1017
|
+
* Create new mrb_state with custom allocators.
|
1018
|
+
*
|
1019
|
+
* @param f
|
1020
|
+
* Reference to the allocation function.
|
1021
|
+
* @param ud
|
1022
|
+
* User data will be passed to custom allocator f.
|
1023
|
+
* If user data isn't required just pass NULL.
|
1024
|
+
* @return
|
1025
|
+
* Pointer to the newly created mrb_state.
|
1026
|
+
*/
|
1027
|
+
MRB_API mrb_state* mrb_open_allocf(mrb_allocf f, void *ud);
|
1028
|
+
|
1029
|
+
/**
|
1030
|
+
* Create new mrb_state with just the MRuby core
|
1031
|
+
*
|
1032
|
+
* @param f
|
1033
|
+
* Reference to the allocation function.
|
1034
|
+
* Use mrb_default_allocf for the default
|
1035
|
+
* @param ud
|
1036
|
+
* User data will be passed to custom allocator f.
|
1037
|
+
* If user data isn't required just pass NULL.
|
1038
|
+
* @return
|
1039
|
+
* Pointer to the newly created mrb_state.
|
1040
|
+
*/
|
1041
|
+
MRB_API mrb_state* mrb_open_core(mrb_allocf f, void *ud);
|
1042
|
+
|
1043
|
+
/**
|
1044
|
+
* Closes and frees a mrb_state.
|
1045
|
+
*
|
1046
|
+
* @param mrb
|
1047
|
+
* Pointer to the mrb_state to be closed.
|
1048
|
+
*/
|
1049
|
+
MRB_API void mrb_close(mrb_state *mrb);
|
1050
|
+
|
1051
|
+
/**
|
1052
|
+
* The default allocation function.
|
1053
|
+
*
|
1054
|
+
* @see mrb_allocf
|
1055
|
+
*/
|
1056
|
+
MRB_API void* mrb_default_allocf(mrb_state*, void*, size_t, void*);
|
1057
|
+
|
1058
|
+
MRB_API mrb_value mrb_top_self(mrb_state *);
|
1059
|
+
MRB_API mrb_value mrb_run(mrb_state*, struct RProc*, mrb_value);
|
1060
|
+
MRB_API mrb_value mrb_top_run(mrb_state*, struct RProc*, mrb_value, unsigned int);
|
1061
|
+
MRB_API mrb_value mrb_vm_run(mrb_state*, struct RProc*, mrb_value, unsigned int);
|
1062
|
+
MRB_API mrb_value mrb_vm_exec(mrb_state*, struct RProc*, mrb_code*);
|
1063
|
+
/* compatibility macros */
|
1064
|
+
#define mrb_toplevel_run_keep(m,p,k) mrb_top_run((m),(p),mrb_top_self(m),(k))
|
1065
|
+
#define mrb_toplevel_run(m,p) mrb_toplevel_run_keep((m),(p),0)
|
1066
|
+
#define mrb_context_run(m,p,s,k) mrb_vm_run((m),(p),(s),(k))
|
1067
|
+
|
1068
|
+
MRB_API void mrb_p(mrb_state*, mrb_value);
|
1069
|
+
MRB_API mrb_int mrb_obj_id(mrb_value obj);
|
1070
|
+
MRB_API mrb_sym mrb_obj_to_sym(mrb_state *mrb, mrb_value name);
|
1071
|
+
|
1072
|
+
MRB_API mrb_bool mrb_obj_eq(mrb_state*, mrb_value, mrb_value);
|
1073
|
+
MRB_API mrb_bool mrb_obj_equal(mrb_state*, mrb_value, mrb_value);
|
1074
|
+
MRB_API mrb_bool mrb_equal(mrb_state *mrb, mrb_value obj1, mrb_value obj2);
|
1075
|
+
MRB_API mrb_value mrb_convert_to_integer(mrb_state *mrb, mrb_value val, mrb_int base);
|
1076
|
+
MRB_API mrb_value mrb_Integer(mrb_state *mrb, mrb_value val);
|
1077
|
+
#ifndef MRB_WITHOUT_FLOAT
|
1078
|
+
MRB_API mrb_value mrb_Float(mrb_state *mrb, mrb_value val);
|
1079
|
+
#endif
|
1080
|
+
MRB_API mrb_value mrb_inspect(mrb_state *mrb, mrb_value obj);
|
1081
|
+
MRB_API mrb_bool mrb_eql(mrb_state *mrb, mrb_value obj1, mrb_value obj2);
|
1082
|
+
|
1083
|
+
static inline int mrb_gc_arena_save(mrb_state*);
|
1084
|
+
static inline void mrb_gc_arena_restore(mrb_state*,int);
|
1085
|
+
|
1086
|
+
static inline int
|
1087
|
+
mrb_gc_arena_save(mrb_state *mrb)
|
1088
|
+
{
|
1089
|
+
return mrb->gc.arena_idx;
|
1090
|
+
}
|
1091
|
+
|
1092
|
+
static inline void
|
1093
|
+
mrb_gc_arena_restore(mrb_state *mrb, int idx)
|
1094
|
+
{
|
1095
|
+
mrb->gc.arena_idx = idx;
|
1096
|
+
}
|
1097
|
+
|
1098
|
+
MRB_API int mrb_gc_arena_save(mrb_state*);
|
1099
|
+
MRB_API void mrb_gc_arena_restore(mrb_state*,int);
|
1100
|
+
|
1101
|
+
MRB_API void mrb_garbage_collect(mrb_state*);
|
1102
|
+
MRB_API void mrb_full_gc(mrb_state*);
|
1103
|
+
MRB_API void mrb_incremental_gc(mrb_state *);
|
1104
|
+
MRB_API void mrb_gc_mark(mrb_state*,struct RBasic*);
|
1105
|
+
#define mrb_gc_mark_value(mrb,val) do {\
|
1106
|
+
if (!mrb_immediate_p(val)) mrb_gc_mark((mrb), mrb_basic_ptr(val)); \
|
1107
|
+
} while (0)
|
1108
|
+
MRB_API void mrb_field_write_barrier(mrb_state *, struct RBasic*, struct RBasic*);
|
1109
|
+
#define mrb_field_write_barrier_value(mrb, obj, val) do{\
|
1110
|
+
if (!mrb_immediate_p(val)) mrb_field_write_barrier((mrb), (obj), mrb_basic_ptr(val)); \
|
1111
|
+
} while (0)
|
1112
|
+
MRB_API void mrb_write_barrier(mrb_state *, struct RBasic*);
|
1113
|
+
|
1114
|
+
MRB_API mrb_value mrb_check_convert_type(mrb_state *mrb, mrb_value val, enum mrb_vtype type, const char *tname, const char *method);
|
1115
|
+
MRB_API mrb_value mrb_any_to_s(mrb_state *mrb, mrb_value obj);
|
1116
|
+
MRB_API const char * mrb_obj_classname(mrb_state *mrb, mrb_value obj);
|
1117
|
+
MRB_API struct RClass* mrb_obj_class(mrb_state *mrb, mrb_value obj);
|
1118
|
+
MRB_API mrb_value mrb_class_path(mrb_state *mrb, struct RClass *c);
|
1119
|
+
MRB_API mrb_value mrb_convert_type(mrb_state *mrb, mrb_value val, enum mrb_vtype type, const char *tname, const char *method);
|
1120
|
+
MRB_API mrb_bool mrb_obj_is_kind_of(mrb_state *mrb, mrb_value obj, struct RClass *c);
|
1121
|
+
MRB_API mrb_value mrb_obj_inspect(mrb_state *mrb, mrb_value self);
|
1122
|
+
MRB_API mrb_value mrb_obj_clone(mrb_state *mrb, mrb_value self);
|
1123
|
+
|
1124
|
+
#ifndef ISPRINT
|
1125
|
+
#define ISASCII(c) ((unsigned)(c) <= 0x7f)
|
1126
|
+
#define ISPRINT(c) (((unsigned)(c) - 0x20) < 0x5f)
|
1127
|
+
#define ISSPACE(c) ((c) == ' ' || (unsigned)(c) - '\t' < 5)
|
1128
|
+
#define ISUPPER(c) (((unsigned)(c) - 'A') < 26)
|
1129
|
+
#define ISLOWER(c) (((unsigned)(c) - 'a') < 26)
|
1130
|
+
#define ISALPHA(c) ((((unsigned)(c) | 0x20) - 'a') < 26)
|
1131
|
+
#define ISDIGIT(c) (((unsigned)(c) - '0') < 10)
|
1132
|
+
#define ISXDIGIT(c) (ISDIGIT(c) || ((unsigned)(c) | 0x20) - 'a' < 6)
|
1133
|
+
#define ISALNUM(c) (ISALPHA(c) || ISDIGIT(c))
|
1134
|
+
#define ISBLANK(c) ((c) == ' ' || (c) == '\t')
|
1135
|
+
#define ISCNTRL(c) ((unsigned)(c) < 0x20 || (c) == 0x7f)
|
1136
|
+
#define TOUPPER(c) (ISLOWER(c) ? ((c) & 0x5f) : (c))
|
1137
|
+
#define TOLOWER(c) (ISUPPER(c) ? ((c) | 0x20) : (c))
|
1138
|
+
#endif
|
1139
|
+
|
1140
|
+
MRB_API mrb_value mrb_exc_new(mrb_state *mrb, struct RClass *c, const char *ptr, size_t len);
|
1141
|
+
MRB_API mrb_noreturn void mrb_exc_raise(mrb_state *mrb, mrb_value exc);
|
1142
|
+
|
1143
|
+
MRB_API mrb_noreturn void mrb_raise(mrb_state *mrb, struct RClass *c, const char *msg);
|
1144
|
+
MRB_API mrb_noreturn void mrb_raisef(mrb_state *mrb, struct RClass *c, const char *fmt, ...);
|
1145
|
+
MRB_API mrb_noreturn void mrb_name_error(mrb_state *mrb, mrb_sym id, const char *fmt, ...);
|
1146
|
+
MRB_API void mrb_warn(mrb_state *mrb, const char *fmt, ...);
|
1147
|
+
MRB_API mrb_noreturn void mrb_bug(mrb_state *mrb, const char *fmt, ...);
|
1148
|
+
MRB_API void mrb_print_backtrace(mrb_state *mrb);
|
1149
|
+
MRB_API void mrb_print_error(mrb_state *mrb);
|
1150
|
+
|
1151
|
+
/* macros to get typical exception objects
|
1152
|
+
note:
|
1153
|
+
+ those E_* macros requires mrb_state* variable named mrb.
|
1154
|
+
+ exception objects obtained from those macros are local to mrb
|
1155
|
+
*/
|
1156
|
+
#define E_RUNTIME_ERROR (mrb_exc_get(mrb, "RuntimeError"))
|
1157
|
+
#define E_TYPE_ERROR (mrb_exc_get(mrb, "TypeError"))
|
1158
|
+
#define E_ARGUMENT_ERROR (mrb_exc_get(mrb, "ArgumentError"))
|
1159
|
+
#define E_INDEX_ERROR (mrb_exc_get(mrb, "IndexError"))
|
1160
|
+
#define E_RANGE_ERROR (mrb_exc_get(mrb, "RangeError"))
|
1161
|
+
#define E_NAME_ERROR (mrb_exc_get(mrb, "NameError"))
|
1162
|
+
#define E_NOMETHOD_ERROR (mrb_exc_get(mrb, "NoMethodError"))
|
1163
|
+
#define E_SCRIPT_ERROR (mrb_exc_get(mrb, "ScriptError"))
|
1164
|
+
#define E_SYNTAX_ERROR (mrb_exc_get(mrb, "SyntaxError"))
|
1165
|
+
#define E_LOCALJUMP_ERROR (mrb_exc_get(mrb, "LocalJumpError"))
|
1166
|
+
#define E_REGEXP_ERROR (mrb_exc_get(mrb, "RegexpError"))
|
1167
|
+
|
1168
|
+
#define E_NOTIMP_ERROR (mrb_exc_get(mrb, "NotImplementedError"))
|
1169
|
+
#ifndef MRB_WITHOUT_FLOAT
|
1170
|
+
#define E_FLOATDOMAIN_ERROR (mrb_exc_get(mrb, "FloatDomainError"))
|
1171
|
+
#endif
|
1172
|
+
|
1173
|
+
#define E_KEY_ERROR (mrb_exc_get(mrb, "KeyError"))
|
1174
|
+
|
1175
|
+
MRB_API mrb_value mrb_yield(mrb_state *mrb, mrb_value b, mrb_value arg);
|
1176
|
+
MRB_API mrb_value mrb_yield_argv(mrb_state *mrb, mrb_value b, mrb_int argc, const mrb_value *argv);
|
1177
|
+
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);
|
1178
|
+
|
1179
|
+
/* continue execution to the proc */
|
1180
|
+
/* this function should always be called as the last function of a method */
|
1181
|
+
/* e.g. return mrb_yield_cont(mrb, proc, self, argc, argv); */
|
1182
|
+
mrb_value mrb_yield_cont(mrb_state *mrb, mrb_value b, mrb_value self, mrb_int argc, const mrb_value *argv);
|
1183
|
+
|
1184
|
+
/* mrb_gc_protect() leaves the object in the arena */
|
1185
|
+
MRB_API void mrb_gc_protect(mrb_state *mrb, mrb_value obj);
|
1186
|
+
/* mrb_gc_register() keeps the object from GC. */
|
1187
|
+
MRB_API void mrb_gc_register(mrb_state *mrb, mrb_value obj);
|
1188
|
+
/* mrb_gc_unregister() removes the object from GC root. */
|
1189
|
+
MRB_API void mrb_gc_unregister(mrb_state *mrb, mrb_value obj);
|
1190
|
+
|
1191
|
+
MRB_API mrb_value mrb_to_int(mrb_state *mrb, mrb_value val);
|
1192
|
+
#define mrb_int(mrb, val) mrb_fixnum(mrb_to_int(mrb, val))
|
1193
|
+
MRB_API void mrb_check_type(mrb_state *mrb, mrb_value x, enum mrb_vtype t);
|
1194
|
+
|
1195
|
+
typedef enum call_type {
|
1196
|
+
CALL_PUBLIC,
|
1197
|
+
CALL_FCALL,
|
1198
|
+
CALL_VCALL,
|
1199
|
+
CALL_TYPE_MAX
|
1200
|
+
} call_type;
|
1201
|
+
|
1202
|
+
MRB_API void mrb_define_alias(mrb_state *mrb, struct RClass *klass, const char *name1, const char *name2);
|
1203
|
+
MRB_API const char *mrb_class_name(mrb_state *mrb, struct RClass* klass);
|
1204
|
+
MRB_API void mrb_define_global_const(mrb_state *mrb, const char *name, mrb_value val);
|
1205
|
+
|
1206
|
+
MRB_API mrb_value mrb_attr_get(mrb_state *mrb, mrb_value obj, mrb_sym id);
|
1207
|
+
|
1208
|
+
MRB_API mrb_bool mrb_respond_to(mrb_state *mrb, mrb_value obj, mrb_sym mid);
|
1209
|
+
MRB_API mrb_bool mrb_obj_is_instance_of(mrb_state *mrb, mrb_value obj, struct RClass* c);
|
1210
|
+
MRB_API mrb_bool mrb_func_basic_p(mrb_state *mrb, mrb_value obj, mrb_sym mid, mrb_func_t func);
|
1211
|
+
|
1212
|
+
|
1213
|
+
/*
|
1214
|
+
* Resume a Fiber
|
1215
|
+
*
|
1216
|
+
* @mrbgem mruby-fiber
|
1217
|
+
*/
|
1218
|
+
MRB_API mrb_value mrb_fiber_resume(mrb_state *mrb, mrb_value fib, mrb_int argc, const mrb_value *argv);
|
1219
|
+
|
1220
|
+
/*
|
1221
|
+
* Yield a Fiber
|
1222
|
+
*
|
1223
|
+
* @mrbgem mruby-fiber
|
1224
|
+
*/
|
1225
|
+
MRB_API mrb_value mrb_fiber_yield(mrb_state *mrb, mrb_int argc, const mrb_value *argv);
|
1226
|
+
|
1227
|
+
/*
|
1228
|
+
* FiberError reference
|
1229
|
+
*
|
1230
|
+
* @mrbgem mruby-fiber
|
1231
|
+
*/
|
1232
|
+
#define E_FIBER_ERROR (mrb_exc_get(mrb, "FiberError"))
|
1233
|
+
|
1234
|
+
/* memory pool implementation */
|
1235
|
+
typedef struct mrb_pool mrb_pool;
|
1236
|
+
MRB_API struct mrb_pool* mrb_pool_open(mrb_state*);
|
1237
|
+
MRB_API void mrb_pool_close(struct mrb_pool*);
|
1238
|
+
MRB_API void* mrb_pool_alloc(struct mrb_pool*, size_t);
|
1239
|
+
MRB_API void* mrb_pool_realloc(struct mrb_pool*, void*, size_t oldlen, size_t newlen);
|
1240
|
+
MRB_API mrb_bool mrb_pool_can_realloc(struct mrb_pool*, void*, size_t);
|
1241
|
+
MRB_API void* mrb_alloca(mrb_state *mrb, size_t);
|
1242
|
+
|
1243
|
+
MRB_API void mrb_state_atexit(mrb_state *mrb, mrb_atexit_func func);
|
1244
|
+
|
1245
|
+
MRB_API void mrb_show_version(mrb_state *mrb);
|
1246
|
+
MRB_API void mrb_show_copyright(mrb_state *mrb);
|
1247
|
+
|
1248
|
+
MRB_API mrb_value mrb_format(mrb_state *mrb, const char *format, ...);
|
1249
|
+
|
1250
|
+
#if 0
|
1251
|
+
/* memcpy and memset does not work with gdb reverse-next on my box */
|
1252
|
+
/* use naive memcpy and memset instead */
|
1253
|
+
#undef memcpy
|
1254
|
+
#undef memset
|
1255
|
+
static void*
|
1256
|
+
mrbmemcpy(void *dst, const void *src, size_t n)
|
1257
|
+
{
|
1258
|
+
char *d = (char*)dst;
|
1259
|
+
const char *s = (const char*)src;
|
1260
|
+
while (n--)
|
1261
|
+
*d++ = *s++;
|
1262
|
+
return d;
|
1263
|
+
}
|
1264
|
+
#define memcpy(a,b,c) mrbmemcpy(a,b,c)
|
1265
|
+
|
1266
|
+
static void*
|
1267
|
+
mrbmemset(void *s, int c, size_t n)
|
1268
|
+
{
|
1269
|
+
char *t = (char*)s;
|
1270
|
+
while (n--)
|
1271
|
+
*t++ = c;
|
1272
|
+
return s;
|
1273
|
+
}
|
1274
|
+
#define memset(a,b,c) mrbmemset(a,b,c)
|
1275
|
+
#endif
|
1276
|
+
|
1277
|
+
MRB_END_DECL
|
1278
|
+
|
1279
|
+
#endif /* MRUBY_H */
|