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

parent c23e68d3
...@@ -210,6 +210,10 @@ void mrb_gc_mark_hash(mrb_state*, struct RHash*); ...@@ -210,6 +210,10 @@ void mrb_gc_mark_hash(mrb_state*, struct RHash*);
size_t mrb_gc_mark_hash_size(mrb_state*, struct RHash*); size_t mrb_gc_mark_hash_size(mrb_state*, struct RHash*);
void mrb_gc_free_hash(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 MRB_END_DECL
#endif /* MRUBY_HASH_H */ #endif /* MRUBY_HASH_H */
...@@ -16,9 +16,6 @@ ...@@ -16,9 +16,6 @@
mrb_int mrb_float_id(mrb_float f); mrb_int mrb_float_id(mrb_float f);
#endif #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 #ifndef MRB_HT_INIT_SIZE
#define MRB_HT_INIT_SIZE 4 #define MRB_HT_INIT_SIZE 4
#endif #endif
...@@ -522,6 +519,13 @@ ht_foreach(mrb_state *mrb, htable *t, ht_foreach_func *func, void *p) ...@@ -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. */ /* Copy the instance variable table. */
static htable* static htable*
ht_copy(mrb_state *mrb, htable *t) ht_copy(mrb_state *mrb, htable *t)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment