Ignore:
Timestamp:
Jul 9, 2020, 8:51:43 AM (4 years ago)
Author:
coas-nagasima
Message:

mrubyを2.1.1に更新

Location:
EcnlProtoTool/trunk/mruby-2.1.1
Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • EcnlProtoTool/trunk/mruby-2.1.1/mrbgems/mruby-class-ext/src/class.c

    r331 r439  
    66mrb_mod_name(mrb_state *mrb, mrb_value self)
    77{
    8   mrb_value name = mrb_class_path(mrb, mrb_class_ptr(self));
    9   return mrb_nil_p(name)? name : mrb_str_dup(mrb, name);
     8  mrb_value name =  mrb_class_path(mrb, mrb_class_ptr(self));
     9  if (mrb_string_p(name)) {
     10    MRB_SET_FROZEN_FLAG(mrb_basic_ptr(name));
     11  }
     12  return name;
     13}
     14
     15static mrb_value
     16mrb_mod_singleton_class_p(mrb_state *mrb, mrb_value self)
     17{
     18  return mrb_bool_value(mrb_sclass_p(self));
     19}
     20
     21/*
     22 *  call-seq:
     23 *     module_exec(arg...) {|var...| block } -> obj
     24 *     class_exec(arg...) {|var...| block } -> obj
     25 *
     26 * Evaluates the given block in the context of the
     27 * class/module. The method defined in the block will belong
     28 * to the receiver. Any arguments passed to the method will be
     29 * passed to the block. This can be used if the block needs to
     30 * access instance variables.
     31 *
     32 *     class Thing
     33 *     end
     34 *     Thing.class_exec{
     35 *       def hello() "Hello there!" end
     36 *     }
     37 *     puts Thing.new.hello()
     38 */
     39
     40static mrb_value
     41mrb_mod_module_exec(mrb_state *mrb, mrb_value self)
     42{
     43  const mrb_value *argv;
     44  mrb_int argc;
     45  mrb_value blk;
     46
     47  mrb_get_args(mrb, "*&!", &argv, &argc, &blk);
     48
     49  mrb->c->ci->target_class = mrb_class_ptr(self);
     50  return mrb_yield_cont(mrb, blk, self, argc, argv);
    1051}
    1152
     
    1657
    1758  mrb_define_method(mrb, mod, "name", mrb_mod_name, MRB_ARGS_NONE());
     59  mrb_define_method(mrb, mod, "singleton_class?", mrb_mod_singleton_class_p, MRB_ARGS_NONE());
     60  mrb_define_method(mrb, mod, "module_exec", mrb_mod_module_exec, MRB_ARGS_ANY()|MRB_ARGS_BLOCK());
     61  mrb_define_method(mrb, mod, "class_exec", mrb_mod_module_exec, MRB_ARGS_ANY()|MRB_ARGS_BLOCK());
    1862}
    1963
Note: See TracChangeset for help on using the changeset viewer.