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
e9231bca
Commit
e9231bca
authored
Jun 20, 2012
by
Yukihiro Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow lambda duplication
parent
88db589e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
4 deletions
+26
-4
src/proc.c
src/proc.c
+26
-4
No files found.
src/proc.c
View file @
e9231bca
...
...
@@ -56,20 +56,40 @@ mrb_proc_new_cfunc(mrb_state *mrb, mrb_func_t func)
return
p
;
}
static
inline
void
proc_copy
(
struct
RProc
*
a
,
struct
RProc
*
b
)
{
a
->
body
=
b
->
body
;
a
->
target_class
=
b
->
target_class
;
a
->
env
=
b
->
env
;
}
static
mrb_value
mrb_proc_initialize
(
mrb_state
*
mrb
,
mrb_value
self
)
{
mrb_value
blk
;
mrb_get_args
(
mrb
,
"&"
,
&
blk
);
if
(
!
mrb_nil_p
(
blk
))
{
*
mrb_proc_ptr
(
self
)
=
*
mrb_proc_ptr
(
blk
);
}
else
{
if
(
mrb_nil_p
(
blk
))
{
/* Calling Proc.new without a block is not implemented yet */
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"tried to create Proc object without a block"
);
}
else
{
proc_copy
(
mrb_proc_ptr
(
self
),
mrb_proc_ptr
(
blk
));
}
return
self
;
}
static
mrb_value
mrb_proc_init_copy
(
mrb_state
*
mrb
,
mrb_value
self
)
{
mrb_value
proc
;
mrb_get_args
(
mrb
,
"o"
,
&
proc
);
if
(
mrb_type
(
proc
)
!=
MRB_TT_PROC
)
{
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"not a proc"
);
}
proc_copy
(
mrb_proc_ptr
(
self
),
mrb_proc_ptr
(
proc
));
return
self
;
}
...
...
@@ -108,8 +128,10 @@ mrb_init_proc(mrb_state *mrb)
call_irep
->
ilen
=
1
;
mrb
->
proc_class
=
mrb_define_class
(
mrb
,
"Proc"
,
mrb
->
object_class
);
MRB_SET_INSTANCE_TT
(
mrb
->
proc_class
,
MRB_TT_PROC
);
mrb_define_method
(
mrb
,
mrb
->
proc_class
,
"initialize"
,
mrb_proc_initialize
,
ARGS_NONE
());
mrb_define_method
(
mrb
,
mrb
->
proc_class
,
"initialize_copy"
,
mrb_proc_init_copy
,
ARGS_REQ
(
1
));
m
=
mrb_proc_new
(
mrb
,
call_irep
);
mrb_define_method_raw
(
mrb
,
mrb
->
proc_class
,
mrb_intern
(
mrb
,
"call"
),
m
);
...
...
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