Add API function `mrb_hash_foreach()` to iterate over items in a hash.
MODIFY
include/mruby/hash.h
include/mruby/hash.h
@@ -210,6 +210,10 @@ void mrb_gc_mark_hash(mrb_state*, struct RHash*);
size_t mrb_gc_mark_hash_size(mrb_state*, struct RHash*);
void mrb_gc_free_hash(mrb_state*, struct RHash*);
+/* return non zero to break the loop */
+typedef int (ht_foreach_func)(mrb_state *mrb, mrb_value key, mrb_value val, void *data);
+MRB_API void mrb_hash_foreach(mrb_state *mrb, struct RHash *hash, ht_foreach_func *func, void *p);
+
MRB_END_DECL
#endif /* MRUBY_HASH_H */

MODIFY
src/hash.c
src/hash.c
mrb_int mrb_float_id(mrb_float f);
#endif
-/* return non zero to break the loop */
-typedef int (ht_foreach_func)(mrb_state *mrb,mrb_value key, mrb_value val, void *data);
-
#ifndef MRB_HT_INIT_SIZE
#define MRB_HT_INIT_SIZE 4
#endif
@@ -522,6 +519,13 @@ ht_foreach(mrb_state *mrb, htable *t, ht_foreach_func *func, void *p)
}
}
+/* Iterates over the instance variable table. */
+MRB_API void
+mrb_hash_foreach(mrb_state *mrb, struct RHash *hash, ht_foreach_func *func, void *p)
+{
+ ht_foreach(mrb, hash->ht, func, p);
+}
+
/* Copy the instance variable table. */
static htable*
ht_copy(mrb_state *mrb, htable *t)

Add API function `mrb_hash_foreach()` to iterate over items in a hash.