Debian Codegraph @

vendor/mruby-source/mrbgems/mruby-metaprog/src/metaprog.c

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