diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2018-12-11 09:48:15 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2018-12-11 09:48:15 +0900 |
| commit | a0df27d8e04f5d042040c794b79b9b213e7092e0 (patch) | |
| tree | 4e6a087ab8297a50720ff15bc20c2d1d984db6bb /src/variable.c | |
| parent | f6b2e6231a1c07438915c2d32ab6002c2a2256b9 (diff) | |
| download | mruby-a0df27d8e04f5d042040c794b79b9b213e7092e0.tar.gz mruby-a0df27d8e04f5d042040c794b79b9b213e7092e0.zip | |
Add new API `mrb_iv_foreach()` to iterate over instance variables.
Diffstat (limited to 'src/variable.c')
| -rw-r--r-- | src/variable.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/variable.c b/src/variable.c index 669a4f5cd..fafec81bd 100644 --- a/src/variable.c +++ b/src/variable.c @@ -9,8 +9,7 @@ #include <mruby/class.h> #include <mruby/proc.h> #include <mruby/string.h> - -typedef int (iv_foreach_func)(mrb_state*,mrb_sym,mrb_value,void*); +#include <mruby/variable.h> #ifndef MRB_IV_SEGMENT_SIZE #define MRB_IV_SEGMENT_SIZE 4 @@ -359,6 +358,14 @@ mrb_obj_iv_set(mrb_state *mrb, struct RObject *obj, mrb_sym sym, mrb_value v) mrb_write_barrier(mrb, (struct RBasic*)obj); } +/* Iterates over the instance variable table. */ +MRB_API void +mrb_iv_foreach(mrb_state *mrb, mrb_value obj, iv_foreach_func *func, void *p) +{ + if (!obj_iv_p(obj)) return; + iv_foreach(mrb, mrb_obj_ptr(obj)->iv, func, p); +} + static inline mrb_bool namespace_p(enum mrb_vtype tt) { |
