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

This commit is contained in:
Yukihiro "Matz" Matsumoto
2018-12-11 09:01:05 +09:00
parent c23e68d32b
commit c0d91a14e7
2 changed files with 11 additions and 3 deletions
+7 -3
View File
@@ -16,9 +16,6 @@
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)