wasm 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/assets/mruby/include/mrbconf.h +143 -0
- data/assets/mruby/include/mruby.h +1284 -0
- data/assets/mruby/include/mruby/array.h +279 -0
- data/assets/mruby/include/mruby/boxing_nan.h +102 -0
- data/assets/mruby/include/mruby/boxing_no.h +56 -0
- data/assets/mruby/include/mruby/boxing_word.h +136 -0
- data/assets/mruby/include/mruby/class.h +94 -0
- data/assets/mruby/include/mruby/common.h +72 -0
- data/assets/mruby/include/mruby/compile.h +194 -0
- data/assets/mruby/include/mruby/data.h +75 -0
- data/assets/mruby/include/mruby/debug.h +66 -0
- data/assets/mruby/include/mruby/dump.h +196 -0
- data/assets/mruby/include/mruby/error.h +75 -0
- data/assets/mruby/include/mruby/gc.h +91 -0
- data/assets/mruby/include/mruby/hash.h +182 -0
- data/assets/mruby/include/mruby/irep.h +62 -0
- data/assets/mruby/include/mruby/istruct.h +47 -0
- data/assets/mruby/include/mruby/khash.h +274 -0
- data/assets/mruby/include/mruby/numeric.h +161 -0
- data/assets/mruby/include/mruby/object.h +45 -0
- data/assets/mruby/include/mruby/opcode.h +161 -0
- data/assets/mruby/include/mruby/proc.h +131 -0
- data/assets/mruby/include/mruby/range.h +49 -0
- data/assets/mruby/include/mruby/re.h +16 -0
- data/assets/mruby/include/mruby/string.h +440 -0
- data/assets/mruby/include/mruby/throw.h +55 -0
- data/assets/mruby/include/mruby/value.h +309 -0
- data/assets/mruby/include/mruby/variable.h +138 -0
- data/assets/mruby/include/mruby/version.h +110 -0
- data/assets/mruby/libmruby.a +0 -0
- data/assets/mruby_init.c +16 -0
- data/assets/template.html +17 -0
- data/bin/ruby-wasm +150 -0
- data/build_config.rb +13 -0
- data/lib/wasm.rb +0 -5
- data/lib/wasm/version.rb +4 -2
- metadata +46 -65
- data/.gitignore +0 -9
- data/.travis.yml +0 -5
- data/Gemfile +0 -4
- data/LICENSE.txt +0 -21
- data/README.md +0 -40
- data/Rakefile +0 -10
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/wasm.gemspec +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dfe951973989d9e59bc9d8bc796947a39e4694bc2d58b57decb6c5d8d7eaeb79
|
4
|
+
data.tar.gz: 1a18804ad9b8a8e0c8cbcdc7f885ac3592d3f4a18cbf81f1768e6ac9d4362602
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52c9851e9a3ecaff84e99e1f45b43080eda668f20f29cc3446931a394a71fae70d7a8f9dd3b786df8a2f23dab0d449cae155ffb04112728d27bfddf6eeb8548e
|
7
|
+
data.tar.gz: b963346298bd3f47d37b65628b0d32630acc69dd44a461a50494810890e94dc761b557584b671ae67a001b361c0d0acc6435b3506711f3da80e7efdf529b8207
|
@@ -0,0 +1,143 @@
|
|
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 to reduce the size of method table */
|
40
|
+
/* MRB_METHOD_TABLE_INLINE requires LSB of function pointers to be zero */
|
41
|
+
/* you might need to specify --falign-functions=n (where n>1) */
|
42
|
+
//#define MRB_METHOD_TABLE_INLINE
|
43
|
+
|
44
|
+
/* add -DMRB_INT16 to use 16bit integer for mrb_int; conflict with MRB_INT64 */
|
45
|
+
//#define MRB_INT16
|
46
|
+
|
47
|
+
/* add -DMRB_INT64 to use 64bit integer for mrb_int; conflict with MRB_INT16 */
|
48
|
+
//#define MRB_INT64
|
49
|
+
|
50
|
+
/* if no specific integer type is chosen */
|
51
|
+
#if !defined(MRB_INT16) && !defined(MRB_INT32) && !defined(MRB_INT64)
|
52
|
+
# if defined(MRB_64BIT) && !defined(MRB_NAN_BOXING)
|
53
|
+
/* Use 64bit integers on 64bit architecture (without MRB_NAN_BOXING) */
|
54
|
+
# define MRB_INT64
|
55
|
+
# else
|
56
|
+
/* Otherwise use 32bit integers */
|
57
|
+
# define MRB_INT32
|
58
|
+
# endif
|
59
|
+
#endif
|
60
|
+
|
61
|
+
/* represent mrb_value in boxed double; conflict with MRB_USE_FLOAT and MRB_WITHOUT_FLOAT */
|
62
|
+
//#define MRB_NAN_BOXING
|
63
|
+
|
64
|
+
/* define on big endian machines; used by MRB_NAN_BOXING */
|
65
|
+
//#define MRB_ENDIAN_BIG
|
66
|
+
|
67
|
+
/* represent mrb_value as a word (natural unit of data for the processor) */
|
68
|
+
//#define MRB_WORD_BOXING
|
69
|
+
|
70
|
+
/* string class to handle UTF-8 encoding */
|
71
|
+
//#define MRB_UTF8_STRING
|
72
|
+
|
73
|
+
/* argv max size in mrb_funcall */
|
74
|
+
//#define MRB_FUNCALL_ARGC_MAX 16
|
75
|
+
|
76
|
+
/* number of object per heap page */
|
77
|
+
//#define MRB_HEAP_PAGE_SIZE 1024
|
78
|
+
|
79
|
+
/* if _etext and _edata available, mruby can reduce memory used by symbols */
|
80
|
+
//#define MRB_USE_ETEXT_EDATA
|
81
|
+
|
82
|
+
/* do not use __init_array_start to determine readonly data section;
|
83
|
+
effective only when MRB_USE_ETEXT_EDATA is defined */
|
84
|
+
//#define MRB_NO_INIT_ARRAY_START
|
85
|
+
|
86
|
+
/* turn off generational GC by default */
|
87
|
+
//#define MRB_GC_TURN_OFF_GENERATIONAL
|
88
|
+
|
89
|
+
/* default size of khash table bucket */
|
90
|
+
//#define KHASH_DEFAULT_SIZE 32
|
91
|
+
|
92
|
+
/* allocated memory address alignment */
|
93
|
+
//#define POOL_ALIGNMENT 4
|
94
|
+
|
95
|
+
/* page size of memory pool */
|
96
|
+
//#define POOL_PAGE_SIZE 16000
|
97
|
+
|
98
|
+
/* initial minimum size for string buffer */
|
99
|
+
//#define MRB_STR_BUF_MIN_SIZE 128
|
100
|
+
|
101
|
+
/* arena size */
|
102
|
+
//#define MRB_GC_ARENA_SIZE 100
|
103
|
+
|
104
|
+
/* fixed size GC arena */
|
105
|
+
//#define MRB_GC_FIXED_ARENA
|
106
|
+
|
107
|
+
/* state atexit stack size */
|
108
|
+
//#define MRB_FIXED_STATE_ATEXIT_STACK_SIZE 5
|
109
|
+
|
110
|
+
/* fixed size state atexit stack */
|
111
|
+
//#define MRB_FIXED_STATE_ATEXIT_STACK
|
112
|
+
|
113
|
+
/* -DMRB_DISABLE_XXXX to drop following features */
|
114
|
+
//#define MRB_DISABLE_STDIO /* use of stdio */
|
115
|
+
|
116
|
+
/* -DMRB_ENABLE_XXXX to enable following features */
|
117
|
+
//#define MRB_ENABLE_DEBUG_HOOK /* hooks for debugger */
|
118
|
+
|
119
|
+
/* end of configuration */
|
120
|
+
|
121
|
+
/* define MRB_DISABLE_XXXX from DISABLE_XXX (for compatibility) */
|
122
|
+
#ifdef DISABLE_STDIO
|
123
|
+
#define MRB_DISABLE_STDIO
|
124
|
+
#endif
|
125
|
+
|
126
|
+
/* define MRB_ENABLE_XXXX from ENABLE_XXX (for compatibility) */
|
127
|
+
#ifdef ENABLE_DEBUG
|
128
|
+
#define MRB_ENABLE_DEBUG_HOOK
|
129
|
+
#endif
|
130
|
+
|
131
|
+
#ifndef MRB_DISABLE_STDIO
|
132
|
+
# include <stdio.h>
|
133
|
+
#endif
|
134
|
+
|
135
|
+
#ifndef FALSE
|
136
|
+
# define FALSE 0
|
137
|
+
#endif
|
138
|
+
|
139
|
+
#ifndef TRUE
|
140
|
+
# define TRUE 1
|
141
|
+
#endif
|
142
|
+
|
143
|
+
#endif /* MRUBYCONF_H */
|
@@ -0,0 +1,1284 @@
|
|
1
|
+
/*
|
2
|
+
** mruby - An embeddable Ruby implementation
|
3
|
+
**
|
4
|
+
** Copyright (c) mruby developers 2010-2018
|
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, *c0;
|
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} | &! raises exception if no block given. |
|
847
|
+
* | `*` | rest arguments | {mrb_value} *, {mrb_int} | Receive the rest of arguments as an array; *! avoid copy of the stack. |
|
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) ((char*)p)
|
1003
|
+
#define mrb_locale_from_utf8(p, l) ((char*)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 void mrb_garbage_collect(mrb_state*);
|
1099
|
+
MRB_API void mrb_full_gc(mrb_state*);
|
1100
|
+
MRB_API void mrb_incremental_gc(mrb_state *);
|
1101
|
+
MRB_API void mrb_gc_mark(mrb_state*,struct RBasic*);
|
1102
|
+
#define mrb_gc_mark_value(mrb,val) do {\
|
1103
|
+
if (!mrb_immediate_p(val)) mrb_gc_mark((mrb), mrb_basic_ptr(val)); \
|
1104
|
+
} while (0)
|
1105
|
+
MRB_API void mrb_field_write_barrier(mrb_state *, struct RBasic*, struct RBasic*);
|
1106
|
+
#define mrb_field_write_barrier_value(mrb, obj, val) do{\
|
1107
|
+
if (!mrb_immediate_p(val)) mrb_field_write_barrier((mrb), (obj), mrb_basic_ptr(val)); \
|
1108
|
+
} while (0)
|
1109
|
+
MRB_API void mrb_write_barrier(mrb_state *, struct RBasic*);
|
1110
|
+
|
1111
|
+
MRB_API mrb_value mrb_check_convert_type(mrb_state *mrb, mrb_value val, enum mrb_vtype type, const char *tname, const char *method);
|
1112
|
+
MRB_API mrb_value mrb_any_to_s(mrb_state *mrb, mrb_value obj);
|
1113
|
+
MRB_API const char * mrb_obj_classname(mrb_state *mrb, mrb_value obj);
|
1114
|
+
MRB_API struct RClass* mrb_obj_class(mrb_state *mrb, mrb_value obj);
|
1115
|
+
MRB_API mrb_value mrb_class_path(mrb_state *mrb, struct RClass *c);
|
1116
|
+
MRB_API mrb_value mrb_convert_type(mrb_state *mrb, mrb_value val, enum mrb_vtype type, const char *tname, const char *method);
|
1117
|
+
MRB_API mrb_bool mrb_obj_is_kind_of(mrb_state *mrb, mrb_value obj, struct RClass *c);
|
1118
|
+
MRB_API mrb_value mrb_obj_inspect(mrb_state *mrb, mrb_value self);
|
1119
|
+
MRB_API mrb_value mrb_obj_clone(mrb_state *mrb, mrb_value self);
|
1120
|
+
|
1121
|
+
#ifndef ISPRINT
|
1122
|
+
#define ISASCII(c) ((unsigned)(c) <= 0x7f)
|
1123
|
+
#define ISPRINT(c) (((unsigned)(c) - 0x20) < 0x5f)
|
1124
|
+
#define ISSPACE(c) ((c) == ' ' || (unsigned)(c) - '\t' < 5)
|
1125
|
+
#define ISUPPER(c) (((unsigned)(c) - 'A') < 26)
|
1126
|
+
#define ISLOWER(c) (((unsigned)(c) - 'a') < 26)
|
1127
|
+
#define ISALPHA(c) ((((unsigned)(c) | 0x20) - 'a') < 26)
|
1128
|
+
#define ISDIGIT(c) (((unsigned)(c) - '0') < 10)
|
1129
|
+
#define ISXDIGIT(c) (ISDIGIT(c) || ((unsigned)(c) | 0x20) - 'a' < 6)
|
1130
|
+
#define ISALNUM(c) (ISALPHA(c) || ISDIGIT(c))
|
1131
|
+
#define ISBLANK(c) ((c) == ' ' || (c) == '\t')
|
1132
|
+
#define ISCNTRL(c) ((unsigned)(c) < 0x20 || (c) == 0x7f)
|
1133
|
+
#define TOUPPER(c) (ISLOWER(c) ? ((c) & 0x5f) : (c))
|
1134
|
+
#define TOLOWER(c) (ISUPPER(c) ? ((c) | 0x20) : (c))
|
1135
|
+
#endif
|
1136
|
+
|
1137
|
+
MRB_API mrb_value mrb_exc_new(mrb_state *mrb, struct RClass *c, const char *ptr, size_t len);
|
1138
|
+
MRB_API mrb_noreturn void mrb_exc_raise(mrb_state *mrb, mrb_value exc);
|
1139
|
+
|
1140
|
+
MRB_API mrb_noreturn void mrb_raise(mrb_state *mrb, struct RClass *c, const char *msg);
|
1141
|
+
MRB_API mrb_noreturn void mrb_raisef(mrb_state *mrb, struct RClass *c, const char *fmt, ...);
|
1142
|
+
MRB_API mrb_noreturn void mrb_name_error(mrb_state *mrb, mrb_sym id, const char *fmt, ...);
|
1143
|
+
MRB_API void mrb_warn(mrb_state *mrb, const char *fmt, ...);
|
1144
|
+
MRB_API mrb_noreturn void mrb_bug(mrb_state *mrb, const char *fmt, ...);
|
1145
|
+
MRB_API void mrb_print_backtrace(mrb_state *mrb);
|
1146
|
+
MRB_API void mrb_print_error(mrb_state *mrb);
|
1147
|
+
|
1148
|
+
/* macros to get typical exception objects
|
1149
|
+
note:
|
1150
|
+
+ those E_* macros requires mrb_state* variable named mrb.
|
1151
|
+
+ exception objects obtained from those macros are local to mrb
|
1152
|
+
*/
|
1153
|
+
#define E_RUNTIME_ERROR (mrb_exc_get(mrb, "RuntimeError"))
|
1154
|
+
#define E_TYPE_ERROR (mrb_exc_get(mrb, "TypeError"))
|
1155
|
+
#define E_ARGUMENT_ERROR (mrb_exc_get(mrb, "ArgumentError"))
|
1156
|
+
#define E_INDEX_ERROR (mrb_exc_get(mrb, "IndexError"))
|
1157
|
+
#define E_RANGE_ERROR (mrb_exc_get(mrb, "RangeError"))
|
1158
|
+
#define E_NAME_ERROR (mrb_exc_get(mrb, "NameError"))
|
1159
|
+
#define E_NOMETHOD_ERROR (mrb_exc_get(mrb, "NoMethodError"))
|
1160
|
+
#define E_SCRIPT_ERROR (mrb_exc_get(mrb, "ScriptError"))
|
1161
|
+
#define E_SYNTAX_ERROR (mrb_exc_get(mrb, "SyntaxError"))
|
1162
|
+
#define E_LOCALJUMP_ERROR (mrb_exc_get(mrb, "LocalJumpError"))
|
1163
|
+
#define E_REGEXP_ERROR (mrb_exc_get(mrb, "RegexpError"))
|
1164
|
+
#define E_FROZEN_ERROR (mrb_exc_get(mrb, "FrozenError"))
|
1165
|
+
|
1166
|
+
#define E_NOTIMP_ERROR (mrb_exc_get(mrb, "NotImplementedError"))
|
1167
|
+
#ifndef MRB_WITHOUT_FLOAT
|
1168
|
+
#define E_FLOATDOMAIN_ERROR (mrb_exc_get(mrb, "FloatDomainError"))
|
1169
|
+
#endif
|
1170
|
+
|
1171
|
+
#define E_KEY_ERROR (mrb_exc_get(mrb, "KeyError"))
|
1172
|
+
|
1173
|
+
MRB_API mrb_value mrb_yield(mrb_state *mrb, mrb_value b, mrb_value arg);
|
1174
|
+
MRB_API mrb_value mrb_yield_argv(mrb_state *mrb, mrb_value b, mrb_int argc, const mrb_value *argv);
|
1175
|
+
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);
|
1176
|
+
|
1177
|
+
/* continue execution to the proc */
|
1178
|
+
/* this function should always be called as the last function of a method */
|
1179
|
+
/* e.g. return mrb_yield_cont(mrb, proc, self, argc, argv); */
|
1180
|
+
mrb_value mrb_yield_cont(mrb_state *mrb, mrb_value b, mrb_value self, mrb_int argc, const mrb_value *argv);
|
1181
|
+
|
1182
|
+
/* mrb_gc_protect() leaves the object in the arena */
|
1183
|
+
MRB_API void mrb_gc_protect(mrb_state *mrb, mrb_value obj);
|
1184
|
+
/* mrb_gc_register() keeps the object from GC. */
|
1185
|
+
MRB_API void mrb_gc_register(mrb_state *mrb, mrb_value obj);
|
1186
|
+
/* mrb_gc_unregister() removes the object from GC root. */
|
1187
|
+
MRB_API void mrb_gc_unregister(mrb_state *mrb, mrb_value obj);
|
1188
|
+
|
1189
|
+
MRB_API mrb_value mrb_to_int(mrb_state *mrb, mrb_value val);
|
1190
|
+
#define mrb_int(mrb, val) mrb_fixnum(mrb_to_int(mrb, val))
|
1191
|
+
MRB_API void mrb_check_type(mrb_state *mrb, mrb_value x, enum mrb_vtype t);
|
1192
|
+
|
1193
|
+
typedef enum call_type {
|
1194
|
+
CALL_PUBLIC,
|
1195
|
+
CALL_FCALL,
|
1196
|
+
CALL_VCALL,
|
1197
|
+
CALL_TYPE_MAX
|
1198
|
+
} call_type;
|
1199
|
+
|
1200
|
+
MRB_API void mrb_define_alias(mrb_state *mrb, struct RClass *klass, const char *name1, const char *name2);
|
1201
|
+
MRB_API const char *mrb_class_name(mrb_state *mrb, struct RClass* klass);
|
1202
|
+
MRB_API void mrb_define_global_const(mrb_state *mrb, const char *name, mrb_value val);
|
1203
|
+
|
1204
|
+
MRB_API mrb_value mrb_attr_get(mrb_state *mrb, mrb_value obj, mrb_sym id);
|
1205
|
+
|
1206
|
+
MRB_API mrb_bool mrb_respond_to(mrb_state *mrb, mrb_value obj, mrb_sym mid);
|
1207
|
+
MRB_API mrb_bool mrb_obj_is_instance_of(mrb_state *mrb, mrb_value obj, struct RClass* c);
|
1208
|
+
MRB_API mrb_bool mrb_func_basic_p(mrb_state *mrb, mrb_value obj, mrb_sym mid, mrb_func_t func);
|
1209
|
+
|
1210
|
+
|
1211
|
+
/*
|
1212
|
+
* Resume a Fiber
|
1213
|
+
*
|
1214
|
+
* @mrbgem mruby-fiber
|
1215
|
+
*/
|
1216
|
+
MRB_API mrb_value mrb_fiber_resume(mrb_state *mrb, mrb_value fib, mrb_int argc, const mrb_value *argv);
|
1217
|
+
|
1218
|
+
/*
|
1219
|
+
* Yield a Fiber
|
1220
|
+
*
|
1221
|
+
* @mrbgem mruby-fiber
|
1222
|
+
*/
|
1223
|
+
MRB_API mrb_value mrb_fiber_yield(mrb_state *mrb, mrb_int argc, const mrb_value *argv);
|
1224
|
+
|
1225
|
+
/*
|
1226
|
+
* Check if a Fiber is alive
|
1227
|
+
*
|
1228
|
+
* @mrbgem mruby-fiber
|
1229
|
+
*/
|
1230
|
+
MRB_API mrb_value mrb_fiber_alive_p(mrb_state *mrb, mrb_value fib);
|
1231
|
+
|
1232
|
+
/*
|
1233
|
+
* FiberError reference
|
1234
|
+
*
|
1235
|
+
* @mrbgem mruby-fiber
|
1236
|
+
*/
|
1237
|
+
#define E_FIBER_ERROR (mrb_exc_get(mrb, "FiberError"))
|
1238
|
+
|
1239
|
+
/* memory pool implementation */
|
1240
|
+
typedef struct mrb_pool mrb_pool;
|
1241
|
+
MRB_API struct mrb_pool* mrb_pool_open(mrb_state*);
|
1242
|
+
MRB_API void mrb_pool_close(struct mrb_pool*);
|
1243
|
+
MRB_API void* mrb_pool_alloc(struct mrb_pool*, size_t);
|
1244
|
+
MRB_API void* mrb_pool_realloc(struct mrb_pool*, void*, size_t oldlen, size_t newlen);
|
1245
|
+
MRB_API mrb_bool mrb_pool_can_realloc(struct mrb_pool*, void*, size_t);
|
1246
|
+
MRB_API void* mrb_alloca(mrb_state *mrb, size_t);
|
1247
|
+
|
1248
|
+
MRB_API void mrb_state_atexit(mrb_state *mrb, mrb_atexit_func func);
|
1249
|
+
|
1250
|
+
MRB_API void mrb_show_version(mrb_state *mrb);
|
1251
|
+
MRB_API void mrb_show_copyright(mrb_state *mrb);
|
1252
|
+
|
1253
|
+
MRB_API mrb_value mrb_format(mrb_state *mrb, const char *format, ...);
|
1254
|
+
|
1255
|
+
#if 0
|
1256
|
+
/* memcpy and memset does not work with gdb reverse-next on my box */
|
1257
|
+
/* use naive memcpy and memset instead */
|
1258
|
+
#undef memcpy
|
1259
|
+
#undef memset
|
1260
|
+
static void*
|
1261
|
+
mrbmemcpy(void *dst, const void *src, size_t n)
|
1262
|
+
{
|
1263
|
+
char *d = (char*)dst;
|
1264
|
+
const char *s = (const char*)src;
|
1265
|
+
while (n--)
|
1266
|
+
*d++ = *s++;
|
1267
|
+
return d;
|
1268
|
+
}
|
1269
|
+
#define memcpy(a,b,c) mrbmemcpy(a,b,c)
|
1270
|
+
|
1271
|
+
static void*
|
1272
|
+
mrbmemset(void *s, int c, size_t n)
|
1273
|
+
{
|
1274
|
+
char *t = (char*)s;
|
1275
|
+
while (n--)
|
1276
|
+
*t++ = c;
|
1277
|
+
return s;
|
1278
|
+
}
|
1279
|
+
#define memset(a,b,c) mrbmemset(a,b,c)
|
1280
|
+
#endif
|
1281
|
+
|
1282
|
+
MRB_END_DECL
|
1283
|
+
|
1284
|
+
#endif /* MRUBY_H */
|