diff options
Diffstat (limited to 'mrbgems/mruby-struct/src')
| -rw-r--r-- | mrbgems/mruby-struct/src/struct.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/mrbgems/mruby-struct/src/struct.c b/mrbgems/mruby-struct/src/struct.c index a15655dbb..6894ffec9 100644 --- a/mrbgems/mruby-struct/src/struct.c +++ b/mrbgems/mruby-struct/src/struct.c @@ -660,11 +660,19 @@ mrb_struct_aset(mrb_state *mrb, mrb_value s) 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)) { return mrb_struct_aset_sym(mrb, s, mrb_symbol(idx), val); } - i = mrb_fixnum(idx); + i = mrb_int(mrb, idx); if (i < 0) i = RSTRUCT_LEN(s) + i; if (i < 0) { mrb_raisef(mrb, E_INDEX_ERROR, |
