Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
a0df27d8
Commit
a0df27d8
authored
Dec 11, 2018
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new API `mrb_iv_foreach()` to iterate over instance variables.
parent
f6b2e623
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
2 deletions
+13
-2
include/mruby/variable.h
include/mruby/variable.h
+4
-0
src/variable.c
src/variable.c
+9
-2
No files found.
include/mruby/variable.h
View file @
a0df27d8
...
...
@@ -131,6 +131,10 @@ void mrb_gc_mark_iv(mrb_state*, struct RObject*);
size_t
mrb_gc_mark_iv_size
(
mrb_state
*
,
struct
RObject
*
);
void
mrb_gc_free_iv
(
mrb_state
*
,
struct
RObject
*
);
/* return non zero to break the loop */
typedef
int
(
iv_foreach_func
)(
mrb_state
*
,
mrb_sym
,
mrb_value
,
void
*
);
MRB_API
void
mrb_iv_foreach
(
mrb_state
*
mrb
,
mrb_value
obj
,
iv_foreach_func
*
func
,
void
*
p
);
MRB_END_DECL
#endif
/* MRUBY_VARIABLE_H */
src/variable.c
View file @
a0df27d8
...
...
@@ -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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment