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
7bc4d08f
Commit
7bc4d08f
authored
May 28, 2014
by
take_cheeze
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support string key in `Struct#[]=`.
parent
0f432e90
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
0 deletions
+10
-0
mrbgems/mruby-struct/src/struct.c
mrbgems/mruby-struct/src/struct.c
+8
-0
mrbgems/mruby-struct/test/struct.rb
mrbgems/mruby-struct/test/struct.rb
+2
-0
No files found.
mrbgems/mruby-struct/src/struct.c
View file @
7bc4d08f
...
@@ -660,6 +660,14 @@ mrb_struct_aset(mrb_state *mrb, mrb_value s)
...
@@ -660,6 +660,14 @@ mrb_struct_aset(mrb_state *mrb, mrb_value s)
mrb_get_args
(
mrb
,
"oo"
,
&
idx
,
&
val
);
mrb_get_args
(
mrb
,
"oo"
,
&
idx
,
&
val
);
if
(
mrb_string_p
(
idx
))
{
mrb_value
sym
=
mrb_check_intern_str
(
mrb
,
idx
);
if
(
mrb_nil_p
(
sym
))
{
mrb_raisef
(
mrb
,
E_INDEX_ERROR
,
"no member '%S' in struct"
,
idx
);
}
idx
=
sym
;
}
if
(
mrb_symbol_p
(
idx
))
{
if
(
mrb_symbol_p
(
idx
))
{
return
mrb_struct_aset_sym
(
mrb
,
s
,
mrb_symbol
(
idx
),
val
);
return
mrb_struct_aset_sym
(
mrb
,
s
,
mrb_symbol
(
idx
),
val
);
}
}
...
...
mrbgems/mruby-struct/test/struct.rb
View file @
7bc4d08f
...
@@ -39,6 +39,8 @@ assert('Struct#[]=', '15.2.18.4.3') do
...
@@ -39,6 +39,8 @@ assert('Struct#[]=', '15.2.18.4.3') do
cc
=
c
.
new
(
1
,
2
)
cc
=
c
.
new
(
1
,
2
)
cc
[
:m1
]
=
3
cc
[
:m1
]
=
3
cc
[
:m1
]
==
3
cc
[
:m1
]
==
3
cc
[
"m2"
]
=
3
assert_equal
3
,
cc
[
"m2"
]
end
end
assert
(
'Struct#each'
,
'15.2.18.4.4'
)
do
assert
(
'Struct#each'
,
'15.2.18.4.4'
)
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