mrb_mt_foreach(mrb_state *mrb, struct RClass *c, mrb_mt_foreach_func *fn, void *p)
{
  mt_tbl *t = c->mt;
  size_t i;

  if (t == NULL) return;
  if (t->alloc == 0) return;
  if (t->size == 0) return;

  for (i=0; i<t->alloc; i++) {
    struct mt_elem *slot = &t->table[i];

    if (slot->key) {
      mrb_method_t m;

      if (slot->func_p) {
        MRB_METHOD_FROM_FUNC(m, slot->ptr.func);
      }
      else {
        MRB_METHOD_FROM_PROC(m, slot->ptr.proc);
      }
      if (slot->noarg_p) {
        MRB_METHOD_NOARG_SET(m);
      }

      if (fn(mrb, slot->key, m, p) != 0)
        return;
    }
  }
  return;
}
mrb_mt_foreach(mrb_state *mrb, struct RClass *c, mrb_mt_foreach_func *fn, void *p)
{
  mt_tbl *t = c->mt;
  size_t i;

  if (t == NULL) return;
  if (t->alloc == 0) return;
  if (t->size == 0) return;

  for (i=0; i<t->alloc; i++) {
    struct mt_elem *slot = &t->table[i];

    if (slot->key) {
      mrb_method_t m;

      if (slot->func_p) {
        MRB_METHOD_FROM_FUNC(m, slot->ptr.func);
      }
      else {
        MRB_METHOD_FROM_PROC(m, slot->ptr.proc);
      }
      if (slot->noarg_p) {
        MRB_METHOD_NOARG_SET(m);
      }

      if (fn(mrb, slot->key, m, p) != 0)
        return;
    }
  }
  return;
}