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
f8aac56d
Commit
f8aac56d
authored
Jul 16, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
git push origin masterMerge branch 'take-cheeze-instance_eval'
parents
d5dd3e94
abf52c77
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
0 deletions
+36
-0
mrbgems/mruby-eval/src/eval.c
mrbgems/mruby-eval/src/eval.c
+26
-0
mrbgems/mruby-eval/test/eval.rb
mrbgems/mruby-eval/test/eval.rb
+10
-0
No files found.
mrbgems/mruby-eval/src/eval.c
View file @
f8aac56d
...
...
@@ -173,10 +173,36 @@ f_eval(mrb_state *mrb, mrb_value self)
return
ret
;
}
mrb_value
mrb_obj_instance_eval
(
mrb_state
*
mrb
,
mrb_value
self
);
static
mrb_value
f_instance_eval
(
mrb_state
*
mrb
,
mrb_value
self
)
{
mrb_value
b
;
mrb_int
argc
;
mrb_value
*
argv
;
mrb_get_args
(
mrb
,
"*&"
,
&
argv
,
&
argc
,
&
b
);
if
(
mrb_nil_p
(
b
))
{
char
*
s
;
mrb_int
len
;
char
*
file
=
NULL
;
mrb_int
line
=
1
;
mrb_get_args
(
mrb
,
"s|zi"
,
&
s
,
&
len
,
&
file
,
&
line
);
return
mrb_run
(
mrb
,
create_proc_from_string
(
mrb
,
s
,
len
,
mrb_nil_value
(),
file
,
line
),
self
);
}
else
{
mrb_get_args
(
mrb
,
"&"
,
&
b
);
return
mrb_obj_instance_eval
(
mrb
,
self
);
}
}
void
mrb_mruby_eval_gem_init
(
mrb_state
*
mrb
)
{
mrb_define_module_function
(
mrb
,
mrb
->
kernel_module
,
"eval"
,
f_eval
,
MRB_ARGS_ARG
(
1
,
3
));
mrb_define_method
(
mrb
,
mrb
->
kernel_module
,
"instance_eval"
,
f_instance_eval
,
MRB_ARGS_ARG
(
1
,
2
));
}
void
...
...
mrbgems/mruby-eval/test/eval.rb
View file @
f8aac56d
...
...
@@ -50,3 +50,13 @@ assert 'eval syntax error' do
eval
'p "test'
end
end
assert
(
'String instance_eval'
)
do
obj
=
Object
.
new
obj
.
instance_variable_set
:@test
,
'test'
assert_raise
(
ArgumentError
)
{
obj
.
instance_eval
(
0
)
{
}
}
assert_raise
(
ArgumentError
)
{
obj
.
instance_eval
(
'0'
,
'test'
,
0
,
'test'
)
}
assert_equal
([
'test.rb'
,
10
])
{
obj
.
instance_eval
(
'[__FILE__, __LINE__]'
,
'test.rb'
,
10
)}
assert_equal
(
'test'
)
{
obj
.
instance_eval
(
'@test'
)
}
assert_equal
(
'test'
)
{
obj
.
instance_eval
{
@test
}
}
end
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