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
0b8a0f4b
Commit
0b8a0f4b
authored
Jul 18, 2014
by
dreamedge
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add Module#module_function
parent
d17506c1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
0 deletions
+48
-0
src/class.c
src/class.c
+38
-0
test/t/module.rb
test/t/module.rb
+10
-0
No files found.
src/class.c
View file @
0b8a0f4b
...
...
@@ -1946,6 +1946,43 @@ mrb_mod_eqq(mrb_state *mrb, mrb_value mod)
return
mrb_bool_value
(
eqq
);
}
mrb_value
mrb_mod_module_function
(
mrb_state
*
mrb
,
mrb_value
mod
)
{
mrb_value
*
argv
;
mrb_int
argc
,
i
;
mrb_sym
mid
;
struct
RProc
*
method_rproc
;
struct
RClass
*
rclass
;
int
ai
;
mrb_check_type
(
mrb
,
mod
,
MRB_TT_MODULE
);
mrb_get_args
(
mrb
,
"*"
,
&
argv
,
&
argc
);
if
(
argc
==
0
)
{
/* set MODFUNC SCOPE if implemented */
return
mod
;
}
/* set PRIVATE method visibility if implemented */
/* mrb_mod_dummy_visibility(mrb, mod); */
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
mrb_check_type
(
mrb
,
argv
[
i
],
MRB_TT_SYMBOL
);
mid
=
mrb_symbol
(
argv
[
i
]);
rclass
=
mrb_class_ptr
(
mod
);
method_rproc
=
mrb_method_search
(
mrb
,
rclass
,
mid
);
prepare_singleton_class
(
mrb
,
(
struct
RBasic
*
)
rclass
);
ai
=
mrb_gc_arena_save
(
mrb
);
mrb_define_method_raw
(
mrb
,
rclass
->
c
,
mid
,
method_rproc
);
mrb_gc_arena_restore
(
mrb
,
ai
);
}
return
mod
;
}
void
mrb_init_class
(
mrb_state
*
mrb
)
{
...
...
@@ -2009,6 +2046,7 @@ mrb_init_class(mrb_state *mrb)
mrb_define_method
(
mrb
,
mod
,
"instance_methods"
,
mrb_mod_instance_methods
,
MRB_ARGS_ANY
());
/* 15.2.2.4.33 */
mrb_define_method
(
mrb
,
mod
,
"method_defined?"
,
mrb_mod_method_defined
,
MRB_ARGS_REQ
(
1
));
/* 15.2.2.4.34 */
mrb_define_method
(
mrb
,
mod
,
"module_eval"
,
mrb_mod_module_eval
,
MRB_ARGS_ANY
());
/* 15.2.2.4.35 */
mrb_define_method
(
mrb
,
mod
,
"module_function"
,
mrb_mod_module_function
,
MRB_ARGS_ANY
());
mrb_define_method
(
mrb
,
mod
,
"private"
,
mrb_mod_dummy_visibility
,
MRB_ARGS_ANY
());
/* 15.2.2.4.36 */
mrb_define_method
(
mrb
,
mod
,
"protected"
,
mrb_mod_dummy_visibility
,
MRB_ARGS_ANY
());
/* 15.2.2.4.37 */
mrb_define_method
(
mrb
,
mod
,
"public"
,
mrb_mod_dummy_visibility
,
MRB_ARGS_ANY
());
/* 15.2.2.4.38 */
...
...
test/t/module.rb
View file @
0b8a0f4b
...
...
@@ -522,3 +522,13 @@ assert('clone Module') do
B
.
new
.
foo
end
assert
(
'Module#module_function'
)
do
module
M
def
modfunc
;
end
module_function
:modfunc
end
assert_true
M
.
respond_to?
(
:modfunc
)
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