source: EcnlProtoTool/trunk/mruby-2.1.1/mrbgems/mruby-metaprog/src/metaprog.c@ 439

Last change on this file since 439 was 439, checked in by coas-nagasima, 4 years ago

mrubyを2.1.1に更新

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc;charset=UTF-8
File size: 19.6 KB
Line 
1#include "mruby.h"
2#include "mruby/array.h"
3#include "mruby/hash.h"
4#include "mruby/variable.h"
5#include "mruby/proc.h"
6#include "mruby/class.h"
7#include "mruby/string.h"
8
9typedef enum {
10 NOEX_PUBLIC = 0x00,
11 NOEX_NOSUPER = 0x01,
12 NOEX_PRIVATE = 0x02,
13 NOEX_PROTECTED = 0x04,
14 NOEX_MASK = 0x06,
15 NOEX_BASIC = 0x08,
16 NOEX_UNDEF = NOEX_NOSUPER,
17 NOEX_MODFUNC = 0x12,
18 NOEX_SUPER = 0x20,
19 NOEX_VCALL = 0x40,
20 NOEX_RESPONDS = 0x80
21} mrb_method_flag_t;
22
23static mrb_value
24mrb_f_nil(mrb_state *mrb, mrb_value cv)
25{
26 return mrb_nil_value();
27}
28
29/* 15.3.1.3.20 */
30/*
31 * call-seq:
32 * obj.instance_variable_defined?(symbol) -> true or false
33 *
34 * Returns <code>true</code> if the given instance variable is
35 * defined in <i>obj</i>.
36 *
37 * class Fred
38 * def initialize(p1, p2)
39 * @a, @b = p1, p2
40 * end
41 * end
42 * fred = Fred.new('cat', 99)
43 * fred.instance_variable_defined?(:@a) #=> true
44 * fred.instance_variable_defined?("@b") #=> true
45 * fred.instance_variable_defined?("@c") #=> false
46 */
47static mrb_value
48mrb_obj_ivar_defined(mrb_state *mrb, mrb_value self)
49{
50 mrb_sym sym;
51
52 mrb_get_args(mrb, "n", &sym);
53 mrb_iv_name_sym_check(mrb, sym);
54 return mrb_bool_value(mrb_iv_defined(mrb, self, sym));
55}
56
57/* 15.3.1.3.21 */
58/*
59 * call-seq:
60 * obj.instance_variable_get(symbol) -> obj
61 *
62 * Returns the value of the given instance variable, or nil if the
63 * instance variable is not set. The <code>@</code> part of the
64 * variable name should be included for regular instance
65 * variables. Throws a <code>NameError</code> exception if the
66 * supplied symbol is not valid as an instance variable name.
67 *
68 * class Fred
69 * def initialize(p1, p2)
70 * @a, @b = p1, p2
71 * end
72 * end
73 * fred = Fred.new('cat', 99)
74 * fred.instance_variable_get(:@a) #=> "cat"
75 * fred.instance_variable_get("@b") #=> 99
76 */
77static mrb_value
78mrb_obj_ivar_get(mrb_state *mrb, mrb_value self)
79{
80 mrb_sym iv_name;
81
82 mrb_get_args(mrb, "n", &iv_name);
83 mrb_iv_name_sym_check(mrb, iv_name);
84 return mrb_iv_get(mrb, self, iv_name);
85}
86
87/* 15.3.1.3.22 */
88/*
89 * call-seq:
90 * obj.instance_variable_set(symbol, obj) -> obj
91 *
92 * Sets the instance variable names by <i>symbol</i> to
93 * <i>object</i>, thereby frustrating the efforts of the class's
94 * author to attempt to provide proper encapsulation. The variable
95 * did not have to exist prior to this call.
96 *
97 * class Fred
98 * def initialize(p1, p2)
99 * @a, @b = p1, p2
100 * end
101 * end
102 * fred = Fred.new('cat', 99)
103 * fred.instance_variable_set(:@a, 'dog') #=> "dog"
104 * fred.instance_variable_set(:@c, 'cat') #=> "cat"
105 * fred.inspect #=> "#<Fred:0x401b3da8 @a=\"dog\", @b=99, @c=\"cat\">"
106 */
107static mrb_value
108mrb_obj_ivar_set(mrb_state *mrb, mrb_value self)
109{
110 mrb_sym iv_name;
111 mrb_value val;
112
113 mrb_get_args(mrb, "no", &iv_name, &val);
114 mrb_iv_name_sym_check(mrb, iv_name);
115 mrb_iv_set(mrb, self, iv_name, val);
116 return val;
117}
118
119/* 15.3.1.2.7 */
120/* 15.3.1.3.28 */
121/*
122 * call-seq:
123 * local_variables -> array
124 *
125 * Returns the names of local variables in the current scope.
126 *
127 * [mruby limitation]
128 * If variable symbol information was stripped out from
129 * compiled binary files using `mruby-strip -l`, this
130 * method always returns an empty array.
131 */
132static mrb_value
133mrb_local_variables(mrb_state *mrb, mrb_value self)
134{
135 struct RProc *proc;
136 mrb_irep *irep;
137 mrb_value vars;
138 size_t i;
139
140 proc = mrb->c->ci[-1].proc;
141
142 if (proc == NULL || MRB_PROC_CFUNC_P(proc)) {
143 return mrb_ary_new(mrb);
144 }
145 vars = mrb_hash_new(mrb);
146 while (proc) {
147 if (MRB_PROC_CFUNC_P(proc)) break;
148 irep = proc->body.irep;
149 if (!irep->lv) break;
150 for (i = 0; i + 1 < irep->nlocals; ++i) {
151 if (irep->lv[i].name) {
152 mrb_sym sym = irep->lv[i].name;
153 const char *name = mrb_sym_name(mrb, sym);
154 switch (name[0]) {
155 case '*': case '&':
156 break;
157 default:
158 mrb_hash_set(mrb, vars, mrb_symbol_value(sym), mrb_true_value());
159 break;
160 }
161 }
162 }
163 if (!MRB_PROC_ENV_P(proc)) break;
164 proc = proc->upper;
165 //if (MRB_PROC_SCOPE_P(proc)) break;
166 if (!proc->c) break;
167 }
168
169 return mrb_hash_keys(mrb, vars);
170}
171
172KHASH_DECLARE(st, mrb_sym, char, FALSE)
173
174static void
175method_entry_loop(mrb_state *mrb, struct RClass *klass, khash_t(st) *set, khash_t(st) *undef)
176{
177 khint_t i;
178
179 khash_t(mt) *h = klass->mt;
180 if (!h || kh_size(h) == 0) return;
181 for (i=0;i<kh_end(h);i++) {
182 if (kh_exist(h, i)) {
183 mrb_method_t m = kh_value(h, i);
184 if (MRB_METHOD_UNDEF_P(m)) {
185 if (undef) {
186 kh_put(st, mrb, undef, kh_key(h, i));
187 }
188 }
189 else if (undef == NULL ||
190 kh_get(st, mrb, undef, kh_key(h, i)) == kh_end(undef)) {
191 kh_put(st, mrb, set, kh_key(h, i));
192 }
193 }
194 }
195}
196
197static mrb_value
198mrb_class_instance_method_list(mrb_state *mrb, mrb_bool recur, struct RClass *klass, int obj)
199{
200 khint_t i;
201 mrb_value ary;
202 mrb_bool prepended = FALSE;
203 struct RClass *oldklass;
204 khash_t(st) *set = kh_init(st, mrb);
205 khash_t(st) *undef = (recur ? kh_init(st, mrb) : NULL);
206
207 if (!recur && (klass->flags & MRB_FL_CLASS_IS_PREPENDED)) {
208 MRB_CLASS_ORIGIN(klass);
209 prepended = TRUE;
210 }
211
212 oldklass = 0;
213 while (klass && (klass != oldklass)) {
214 method_entry_loop(mrb, klass, set, undef);
215 if ((klass->tt == MRB_TT_ICLASS && !prepended) ||
216 (klass->tt == MRB_TT_SCLASS)) {
217 }
218 else {
219 if (!recur) break;
220 }
221 oldklass = klass;
222 klass = klass->super;
223 }
224
225 ary = mrb_ary_new_capa(mrb, kh_size(set));
226 for (i=0;i<kh_end(set);i++) {
227 if (kh_exist(set, i)) {
228 mrb_ary_push(mrb, ary, mrb_symbol_value(kh_key(set, i)));
229 }
230 }
231 kh_destroy(st, mrb, set);
232 if (undef) kh_destroy(st, mrb, undef);
233
234 return ary;
235}
236
237static mrb_value
238mrb_obj_methods(mrb_state *mrb, mrb_bool recur, mrb_value obj, mrb_method_flag_t flag)
239{
240 return mrb_class_instance_method_list(mrb, recur, mrb_class(mrb, obj), 0);
241}
242/* 15.3.1.3.31 */
243/*
244 * call-seq:
245 * obj.methods -> array
246 *
247 * Returns a list of the names of methods publicly accessible in
248 * <i>obj</i>. This will include all the methods accessible in
249 * <i>obj</i>'s ancestors.
250 *
251 * class Klass
252 * def kMethod()
253 * end
254 * end
255 * k = Klass.new
256 * k.methods[0..9] #=> [:kMethod, :respond_to?, :nil?, :is_a?,
257 * # :class, :instance_variable_set,
258 * # :methods, :extend, :__send__, :instance_eval]
259 * k.methods.length #=> 42
260 */
261static mrb_value
262mrb_obj_methods_m(mrb_state *mrb, mrb_value self)
263{
264 mrb_bool recur = TRUE;
265 mrb_get_args(mrb, "|b", &recur);
266 return mrb_obj_methods(mrb, recur, self, (mrb_method_flag_t)0); /* everything but private */
267}
268
269/* 15.3.1.3.36 */
270/*
271 * call-seq:
272 * obj.private_methods(all=true) -> array
273 *
274 * Returns the list of private methods accessible to <i>obj</i>. If
275 * the <i>all</i> parameter is set to <code>false</code>, only those methods
276 * in the receiver will be listed.
277 */
278static mrb_value
279mrb_obj_private_methods(mrb_state *mrb, mrb_value self)
280{
281 mrb_bool recur = TRUE;
282 mrb_get_args(mrb, "|b", &recur);
283 return mrb_obj_methods(mrb, recur, self, NOEX_PRIVATE); /* private attribute not define */
284}
285
286/* 15.3.1.3.37 */
287/*
288 * call-seq:
289 * obj.protected_methods(all=true) -> array
290 *
291 * Returns the list of protected methods accessible to <i>obj</i>. If
292 * the <i>all</i> parameter is set to <code>false</code>, only those methods
293 * in the receiver will be listed.
294 */
295static mrb_value
296mrb_obj_protected_methods(mrb_state *mrb, mrb_value self)
297{
298 mrb_bool recur = TRUE;
299 mrb_get_args(mrb, "|b", &recur);
300 return mrb_obj_methods(mrb, recur, self, NOEX_PROTECTED); /* protected attribute not define */
301}
302
303/* 15.3.1.3.38 */
304/*
305 * call-seq:
306 * obj.public_methods(all=true) -> array
307 *
308 * Returns the list of public methods accessible to <i>obj</i>. If
309 * the <i>all</i> parameter is set to <code>false</code>, only those methods
310 * in the receiver will be listed.
311 */
312static mrb_value
313mrb_obj_public_methods(mrb_state *mrb, mrb_value self)
314{
315 mrb_bool recur = TRUE;
316 mrb_get_args(mrb, "|b", &recur);
317 return mrb_obj_methods(mrb, recur, self, NOEX_PUBLIC); /* public attribute not define */
318}
319
320static mrb_value
321mrb_obj_singleton_methods(mrb_state *mrb, mrb_bool recur, mrb_value obj)
322{
323 khint_t i;
324 mrb_value ary;
325 struct RClass *klass;
326 khash_t(st) *set = kh_init(st, mrb);
327 khash_t(st) *undef = (recur ? kh_init(st, mrb) : NULL);
328
329 klass = mrb_class(mrb, obj);
330
331 if (klass && (klass->tt == MRB_TT_SCLASS)) {
332 method_entry_loop(mrb, klass, set, undef);
333 klass = klass->super;
334 }
335 if (recur) {
336 while (klass && ((klass->tt == MRB_TT_SCLASS) || (klass->tt == MRB_TT_ICLASS))) {
337 method_entry_loop(mrb, klass, set, undef);
338 klass = klass->super;
339 }
340 }
341
342 ary = mrb_ary_new(mrb);
343 for (i=0;i<kh_end(set);i++) {
344 if (kh_exist(set, i)) {
345 mrb_ary_push(mrb, ary, mrb_symbol_value(kh_key(set, i)));
346 }
347 }
348 kh_destroy(st, mrb, set);
349 if (undef) kh_destroy(st, mrb, undef);
350
351 return ary;
352}
353
354/* 15.3.1.3.45 */
355/*
356 * call-seq:
357 * obj.singleton_methods(all=true) -> array
358 *
359 * Returns an array of the names of singleton methods for <i>obj</i>.
360 * If the optional <i>all</i> parameter is true, the list will include
361 * methods in modules included in <i>obj</i>.
362 * Only public and protected singleton methods are returned.
363 *
364 * module Other
365 * def three() end
366 * end
367 *
368 * class Single
369 * def Single.four() end
370 * end
371 *
372 * a = Single.new
373 *
374 * def a.one()
375 * end
376 *
377 * class << a
378 * include Other
379 * def two()
380 * end
381 * end
382 *
383 * Single.singleton_methods #=> [:four]
384 * a.singleton_methods(false) #=> [:two, :one]
385 * a.singleton_methods #=> [:two, :one, :three]
386 */
387static mrb_value
388mrb_obj_singleton_methods_m(mrb_state *mrb, mrb_value self)
389{
390 mrb_bool recur = TRUE;
391 mrb_get_args(mrb, "|b", &recur);
392 return mrb_obj_singleton_methods(mrb, recur, self);
393}
394
395static mrb_value
396mod_define_singleton_method(mrb_state *mrb, mrb_value self)
397{
398 struct RProc *p;
399 mrb_method_t m;
400 mrb_sym mid;
401 mrb_value blk = mrb_nil_value();
402
403 mrb_get_args(mrb, "n&!", &mid, &blk);
404 p = (struct RProc*)mrb_obj_alloc(mrb, MRB_TT_PROC, mrb->proc_class);
405 mrb_proc_copy(p, mrb_proc_ptr(blk));
406 p->flags |= MRB_PROC_STRICT;
407 MRB_METHOD_FROM_PROC(m, p);
408 mrb_define_method_raw(mrb, mrb_class_ptr(mrb_singleton_class(mrb, self)), mid, m);
409 return mrb_symbol_value(mid);
410}
411
412static mrb_bool
413cv_name_p(mrb_state *mrb, const char *name, mrb_int len)
414{
415 return len > 2 && name[0] == '@' && name[1] == '@' &&
416 !ISDIGIT(name[2]) && mrb_ident_p(name+2, len-2);
417}
418
419static void
420check_cv_name_sym(mrb_state *mrb, mrb_sym id)
421{
422 mrb_int len;
423 const char *name = mrb_sym_name_len(mrb, id, &len);
424 if (!cv_name_p(mrb, name, len)) {
425 mrb_name_error(mrb, id, "'%n' is not allowed as a class variable name", id);
426 }
427}
428
429/* 15.2.2.4.39 */
430/*
431 * call-seq:
432 * remove_class_variable(sym) -> obj
433 *
434 * Removes the definition of the <i>sym</i>, returning that
435 * constant's value.
436 *
437 * class Dummy
438 * @@var = 99
439 * puts @@var
440 * p class_variables
441 * remove_class_variable(:@@var)
442 * p class_variables
443 * end
444 *
445 * <em>produces:</em>
446 *
447 * 99
448 * [:@@var]
449 * []
450 */
451
452static mrb_value
453mrb_mod_remove_cvar(mrb_state *mrb, mrb_value mod)
454{
455 mrb_value val;
456 mrb_sym id;
457
458 mrb_get_args(mrb, "n", &id);
459 check_cv_name_sym(mrb, id);
460
461 val = mrb_iv_remove(mrb, mod, id);
462 if (!mrb_undef_p(val)) return val;
463
464 if (mrb_cv_defined(mrb, mod, id)) {
465 mrb_name_error(mrb, id, "cannot remove %n for %v", id, mod);
466 }
467
468 mrb_name_error(mrb, id, "class variable %n not defined for %v", id, mod);
469
470 /* not reached */
471 return mrb_nil_value();
472}
473
474/* 15.2.2.4.16 */
475/*
476 * call-seq:
477 * obj.class_variable_defined?(symbol) -> true or false
478 *
479 * Returns <code>true</code> if the given class variable is defined
480 * in <i>obj</i>.
481 *
482 * class Fred
483 * @@foo = 99
484 * end
485 * Fred.class_variable_defined?(:@@foo) #=> true
486 * Fred.class_variable_defined?(:@@bar) #=> false
487 */
488
489static mrb_value
490mrb_mod_cvar_defined(mrb_state *mrb, mrb_value mod)
491{
492 mrb_sym id;
493
494 mrb_get_args(mrb, "n", &id);
495 check_cv_name_sym(mrb, id);
496 return mrb_bool_value(mrb_cv_defined(mrb, mod, id));
497}
498
499/* 15.2.2.4.17 */
500/*
501 * call-seq:
502 * mod.class_variable_get(symbol) -> obj
503 *
504 * Returns the value of the given class variable (or throws a
505 * <code>NameError</code> exception). The <code>@@</code> part of the
506 * variable name should be included for regular class variables
507 *
508 * class Fred
509 * @@foo = 99
510 * end
511 * Fred.class_variable_get(:@@foo) #=> 99
512 */
513
514static mrb_value
515mrb_mod_cvar_get(mrb_state *mrb, mrb_value mod)
516{
517 mrb_sym id;
518
519 mrb_get_args(mrb, "n", &id);
520 check_cv_name_sym(mrb, id);
521 return mrb_cv_get(mrb, mod, id);
522}
523
524/* 15.2.2.4.18 */
525/*
526 * call-seq:
527 * obj.class_variable_set(symbol, obj) -> obj
528 *
529 * Sets the class variable names by <i>symbol</i> to
530 * <i>object</i>.
531 *
532 * class Fred
533 * @@foo = 99
534 * def foo
535 * @@foo
536 * end
537 * end
538 * Fred.class_variable_set(:@@foo, 101) #=> 101
539 * Fred.new.foo #=> 101
540 */
541
542static mrb_value
543mrb_mod_cvar_set(mrb_state *mrb, mrb_value mod)
544{
545 mrb_value value;
546 mrb_sym id;
547
548 mrb_get_args(mrb, "no", &id, &value);
549 check_cv_name_sym(mrb, id);
550 mrb_cv_set(mrb, mod, id, value);
551 return value;
552}
553
554static mrb_value
555mrb_mod_included_modules(mrb_state *mrb, mrb_value self)
556{
557 mrb_value result;
558 struct RClass *c = mrb_class_ptr(self);
559 struct RClass *origin = c;
560
561 MRB_CLASS_ORIGIN(origin);
562 result = mrb_ary_new(mrb);
563 while (c) {
564 if (c != origin && c->tt == MRB_TT_ICLASS) {
565 if (c->c->tt == MRB_TT_MODULE) {
566 mrb_ary_push(mrb, result, mrb_obj_value(c->c));
567 }
568 }
569 c = c->super;
570 }
571
572 return result;
573}
574
575/* 15.2.2.4.33 */
576/*
577 * call-seq:
578 * mod.instance_methods(include_super=true) -> array
579 *
580 * Returns an array containing the names of the public and protected instance
581 * methods in the receiver. For a module, these are the public and protected methods;
582 * for a class, they are the instance (not singleton) methods. With no
583 * argument, or with an argument that is <code>false</code>, the
584 * instance methods in <i>mod</i> are returned, otherwise the methods
585 * in <i>mod</i> and <i>mod</i>'s superclasses are returned.
586 *
587 * module A
588 * def method1() end
589 * end
590 * class B
591 * def method2() end
592 * end
593 * class C < B
594 * def method3() end
595 * end
596 *
597 * A.instance_methods #=> [:method1]
598 * B.instance_methods(false) #=> [:method2]
599 * C.instance_methods(false) #=> [:method3]
600 * C.instance_methods(true).length #=> 43
601 */
602
603static mrb_value
604mrb_mod_instance_methods(mrb_state *mrb, mrb_value mod)
605{
606 struct RClass *c = mrb_class_ptr(mod);
607 mrb_bool recur = TRUE;
608 mrb_get_args(mrb, "|b", &recur);
609 return mrb_class_instance_method_list(mrb, recur, c, 0);
610}
611
612static void
613remove_method(mrb_state *mrb, mrb_value mod, mrb_sym mid)
614{
615 struct RClass *c = mrb_class_ptr(mod);
616 khash_t(mt) *h;
617 khiter_t k;
618
619 MRB_CLASS_ORIGIN(c);
620 h = c->mt;
621
622 if (h) {
623 k = kh_get(mt, mrb, h, mid);
624 if (k != kh_end(h)) {
625 kh_del(mt, mrb, h, k);
626 mrb_funcall(mrb, mod, "method_removed", 1, mrb_symbol_value(mid));
627 return;
628 }
629 }
630
631 mrb_name_error(mrb, mid, "method '%n' not defined in %v", mid, mod);
632}
633
634/* 15.2.2.4.41 */
635/*
636 * call-seq:
637 * remove_method(symbol) -> self
638 *
639 * Removes the method identified by _symbol_ from the current
640 * class. For an example, see <code>Module.undef_method</code>.
641 */
642
643static mrb_value
644mrb_mod_remove_method(mrb_state *mrb, mrb_value mod)
645{
646 mrb_int argc;
647 mrb_value *argv;
648
649 mrb_get_args(mrb, "*", &argv, &argc);
650 mrb_check_frozen(mrb, mrb_obj_ptr(mod));
651 while (argc--) {
652 remove_method(mrb, mod, mrb_obj_to_sym(mrb, *argv));
653 argv++;
654 }
655 return mod;
656}
657
658static mrb_value
659mrb_mod_s_constants(mrb_state *mrb, mrb_value mod)
660{
661 mrb_raise(mrb, E_NOTIMP_ERROR, "Module.constants not implemented");
662 return mrb_nil_value(); /* not reached */
663}
664
665static mrb_value
666mrb_mod_s_nesting(mrb_state *mrb, mrb_value mod)
667{
668 struct RProc *proc;
669 mrb_value ary;
670 struct RClass *c = NULL;
671
672 ary = mrb_ary_new(mrb);
673 proc = mrb->c->ci[-1].proc; /* callee proc */
674 mrb_assert(!MRB_PROC_CFUNC_P(proc));
675 while (proc) {
676 if (MRB_PROC_SCOPE_P(proc)) {
677 struct RClass *c2 = MRB_PROC_TARGET_CLASS(proc);
678
679 if (c2 != c) {
680 c = c2;
681 mrb_ary_push(mrb, ary, mrb_obj_value(c));
682 }
683 }
684 proc = proc->upper;
685 }
686 return ary;
687}
688
689void
690mrb_mruby_metaprog_gem_init(mrb_state* mrb)
691{
692 struct RClass *krn = mrb->kernel_module;
693 struct RClass *mod = mrb->module_class;
694
695 mrb_define_method(mrb, krn, "global_variables", mrb_f_global_variables, MRB_ARGS_NONE()); /* 15.3.1.3.14 (15.3.1.2.4) */
696 mrb_define_method(mrb, krn, "local_variables", mrb_local_variables, MRB_ARGS_NONE()); /* 15.3.1.3.28 (15.3.1.2.7) */
697
698 mrb_define_method(mrb, krn, "singleton_class", mrb_singleton_class, MRB_ARGS_NONE());
699 mrb_define_method(mrb, krn, "instance_variable_defined?", mrb_obj_ivar_defined, MRB_ARGS_REQ(1)); /* 15.3.1.3.20 */
700 mrb_define_method(mrb, krn, "instance_variable_get", mrb_obj_ivar_get, MRB_ARGS_REQ(1)); /* 15.3.1.3.21 */
701 mrb_define_method(mrb, krn, "instance_variable_set", mrb_obj_ivar_set, MRB_ARGS_REQ(2)); /* 15.3.1.3.22 */
702 mrb_define_method(mrb, krn, "instance_variables", mrb_obj_instance_variables, MRB_ARGS_NONE()); /* 15.3.1.3.23 */
703 mrb_define_method(mrb, krn, "methods", mrb_obj_methods_m, MRB_ARGS_OPT(1)); /* 15.3.1.3.31 */
704 mrb_define_method(mrb, krn, "private_methods", mrb_obj_private_methods, MRB_ARGS_OPT(1)); /* 15.3.1.3.36 */
705 mrb_define_method(mrb, krn, "protected_methods", mrb_obj_protected_methods, MRB_ARGS_OPT(1)); /* 15.3.1.3.37 */
706 mrb_define_method(mrb, krn, "public_methods", mrb_obj_public_methods, MRB_ARGS_OPT(1)); /* 15.3.1.3.38 */
707 mrb_define_method(mrb, krn, "singleton_methods", mrb_obj_singleton_methods_m, MRB_ARGS_OPT(1)); /* 15.3.1.3.45 */
708 mrb_define_method(mrb, krn, "define_singleton_method", mod_define_singleton_method, MRB_ARGS_REQ(1)|MRB_ARGS_BLOCK());
709 mrb_define_method(mrb, krn, "send", mrb_f_send, MRB_ARGS_REQ(1)|MRB_ARGS_REST()|MRB_ARGS_BLOCK()); /* 15.3.1.3.44 */
710
711 mrb_define_method(mrb, mod, "class_variables", mrb_mod_class_variables, MRB_ARGS_OPT(1)); /* 15.2.2.4.19 */
712 mrb_define_method(mrb, mod, "remove_class_variable", mrb_mod_remove_cvar, MRB_ARGS_REQ(1)); /* 15.2.2.4.39 */
713 mrb_define_method(mrb, mod, "class_variable_defined?", mrb_mod_cvar_defined, MRB_ARGS_REQ(1)); /* 15.2.2.4.16 */
714 mrb_define_method(mrb, mod, "class_variable_get", mrb_mod_cvar_get, MRB_ARGS_REQ(1)); /* 15.2.2.4.17 */
715 mrb_define_method(mrb, mod, "class_variable_set", mrb_mod_cvar_set, MRB_ARGS_REQ(2)); /* 15.2.2.4.18 */
716 mrb_define_method(mrb, mod, "included_modules", mrb_mod_included_modules, MRB_ARGS_NONE()); /* 15.2.2.4.30 */
717 mrb_define_method(mrb, mod, "instance_methods", mrb_mod_instance_methods, MRB_ARGS_ANY()); /* 15.2.2.4.33 */
718 mrb_define_method(mrb, mod, "remove_method", mrb_mod_remove_method, MRB_ARGS_ANY()); /* 15.2.2.4.41 */
719 mrb_define_method(mrb, mod, "method_removed", mrb_f_nil, MRB_ARGS_REQ(1));
720 mrb_define_method(mrb, mod, "constants", mrb_mod_constants, MRB_ARGS_OPT(1)); /* 15.2.2.4.24 */
721 mrb_define_class_method(mrb, mod, "constants", mrb_mod_s_constants, MRB_ARGS_ANY()); /* 15.2.2.3.1 */
722 mrb_define_class_method(mrb, mod, "nesting", mrb_mod_s_nesting, MRB_ARGS_NONE()); /* 15.2.2.3.2 */
723}
724
725void
726mrb_mruby_metaprog_gem_final(mrb_state* mrb)
727{
728}
Note: See TracBrowser for help on using the repository browser.