Exemplo n.º 1
0
  std::string Module::debug_str(STATE) {
    Symbol* name = module_name();

    if(name->nil_p()) {
      return "<anonymous module>";
    } else {
      return name->cpp_str(state);
    }
  }
Exemplo n.º 2
0
  Class* Module::mirror(STATE, Object* obj) {
    Class* object_class = obj->class_object(state);
    Class* mirror = object_class->mirror();

    if(!mirror->nil_p()) return mirror;

    Class* klass = object_class;

    do {
      Symbol* name = klass->module_name();

      if(!name->nil_p()) {
        std::string class_name = name->cpp_str(state);
        size_t k = class_name.rfind("::");
        if(k != std::string::npos) {
          class_name = class_name.substr(k);
        }

        bool found = false;
        Object* obj = G(mirror)->get_const(state, state->symbol(class_name), &found);

        if(found) {
          if(Class* mirror_class = try_as<Class>(obj)) {
            object_class->mirror(state, mirror_class);
            return mirror_class;
          }
        }
      }

      Module* ancestor = klass->superclass();
      klass = 0;

      while(!ancestor->nil_p()) {
        if((klass = try_as<Class>(ancestor))) break;
        ancestor = ancestor->superclass();
      }
    } while(klass);

    return nil<Class>();
  }