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
fc80e4b6
Commit
fc80e4b6
authored
May 31, 2020
by
dearblue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Get local variable names from orphan block; ref #3710
parent
d5cca2bd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
14 deletions
+22
-14
mrbgems/mruby-metaprog/src/metaprog.c
mrbgems/mruby-metaprog/src/metaprog.c
+13
-14
mrbgems/mruby-metaprog/test/metaprog.rb
mrbgems/mruby-metaprog/test/metaprog.rb
+9
-0
No files found.
mrbgems/mruby-metaprog/src/metaprog.c
View file @
fc80e4b6
...
@@ -146,24 +146,23 @@ mrb_local_variables(mrb_state *mrb, mrb_value self)
...
@@ -146,24 +146,23 @@ mrb_local_variables(mrb_state *mrb, mrb_value self)
while
(
proc
)
{
while
(
proc
)
{
if
(
MRB_PROC_CFUNC_P
(
proc
))
break
;
if
(
MRB_PROC_CFUNC_P
(
proc
))
break
;
irep
=
proc
->
body
.
irep
;
irep
=
proc
->
body
.
irep
;
if
(
!
irep
->
lv
)
break
;
if
(
irep
->
lv
)
{
for
(
i
=
0
;
i
+
1
<
irep
->
nlocals
;
++
i
)
{
for
(
i
=
0
;
i
+
1
<
irep
->
nlocals
;
++
i
)
{
if
(
irep
->
lv
[
i
].
name
)
{
if
(
irep
->
lv
[
i
].
name
)
{
mrb_sym
sym
=
irep
->
lv
[
i
].
name
;
mrb_sym
sym
=
irep
->
lv
[
i
].
name
;
const
char
*
name
=
mrb_sym_name
(
mrb
,
sym
);
const
char
*
name
=
mrb_sym_name
(
mrb
,
sym
);
switch
(
name
[
0
])
{
switch
(
name
[
0
])
{
case
'*'
:
case
'&'
:
case
'*'
:
case
'&'
:
break
;
break
;
default:
default:
mrb_hash_set
(
mrb
,
vars
,
mrb_symbol_value
(
sym
),
mrb_true_value
());
mrb_hash_set
(
mrb
,
vars
,
mrb_symbol_value
(
sym
),
mrb_true_value
());
break
;
break
;
}
}
}
}
}
}
}
if
(
!
MRB_PROC_ENV
_P
(
proc
))
break
;
if
(
MRB_PROC_SCOPE
_P
(
proc
))
break
;
proc
=
proc
->
upper
;
proc
=
proc
->
upper
;
//if (MRB_PROC_SCOPE_P(proc)) break;
if
(
!
proc
->
c
)
break
;
}
}
return
mrb_hash_keys
(
mrb
,
vars
);
return
mrb_hash_keys
(
mrb
,
vars
);
...
...
mrbgems/mruby-metaprog/test/metaprog.rb
View file @
fc80e4b6
...
@@ -114,6 +114,15 @@ assert('Kernel.local_variables', '15.3.1.2.7') do
...
@@ -114,6 +114,15 @@ assert('Kernel.local_variables', '15.3.1.2.7') do
# Kernel#local_variables: 15.3.1.3.28
# Kernel#local_variables: 15.3.1.3.28
local_variables
.
sort
local_variables
.
sort
}.
call
(
-
1
,
-
2
)
}.
call
(
-
1
,
-
2
)
a
=
Object
.
new
def
a
.
hoge
(
vars
,
*
,
**
)
Proc
.
new
{
x
,
y
=
1
,
2
local_variables
.
sort
}
end
assert_equal
([
:vars
,
:x
,
:y
])
{
a
.
hoge
(
0
).
call
}
end
end
assert
(
'Kernel#define_singleton_method'
)
do
assert
(
'Kernel#define_singleton_method'
)
do
...
...
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