summaryrefslogtreecommitdiffhomepage
path: root/src/hash.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2018-12-11 09:01:05 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2018-12-11 09:01:05 +0900
commitc0d91a14e78de39b3940e56d4cccdbdb17b65694 (patch)
tree2776a281b3bc7a2846ca189a36a2eb6d9d7463fd /src/hash.c
parentc23e68d32b8913f35e344844805d1b80f5633ecd (diff)
downloadmruby-c0d91a14e78de39b3940e56d4cccdbdb17b65694.tar.gz
mruby-c0d91a14e78de39b3940e56d4cccdbdb17b65694.zip
Add API function `mrb_hash_foreach()` to iterate over items in a hash.
Diffstat (limited to 'src/hash.c')
-rw-r--r--src/hash.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/hash.c b/src/hash.c
index 467b20a51..00d5ad2b1 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -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)