From 2ce6d23db628df3eef3a5bda0091768bccdbe9cd Mon Sep 17 00:00:00 2001 From: dearblue Date: Sun, 4 Mar 2018 22:23:47 +0900 Subject: add forced block arguments feature to mrb_get_args --- include/mruby.h | 2 +- src/class.c | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/mruby.h b/include/mruby.h index ab6b5b3d6..8fc2721b1 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -843,7 +843,7 @@ MRB_API struct RClass * mrb_define_module_under(mrb_state *mrb, struct RClass *o * | `i` | {Integer} | {mrb_int} | | * | `b` | boolean | {mrb_bool} | | * | `n` | {Symbol} | {mrb_sym} | | - * | `&` | block | {mrb_value} | | + * | `&` | block | {mrb_value} | when && gives raised exception if no block given. | * | `*` | rest arguments | {mrb_value} *, {mrb_int} | Receive the rest of arguments as an array. | * | | | optional | | After this spec following specs would be optional. | * | `?` | optional given | {mrb_bool} | `TRUE` if preceding argument is given. Used to check optional argument is given. | diff --git a/src/class.c b/src/class.c index 3f24528ca..e0f8d4673 100644 --- a/src/class.c +++ b/src/class.c @@ -593,7 +593,7 @@ mrb_get_argv(mrb_state *mrb) n: Symbol [mrb_sym] d: Data [void*,mrb_data_type const] 2nd argument will be used to check data type so it won't be modified I: Inline struct [void*] - &: Block [mrb_value] + &: Block [mrb_value] when && gives raised exception if no block given *: rest argument [mrb_value*,mrb_int] The rest of the arguments as an array; *! avoid copy of the stack |: optional Following arguments are optional ?: optional given [mrb_bool] true if preceding argument (optional) is given @@ -937,6 +937,12 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) else { bp = mrb->c->stack + mrb->c->ci->argc + 1; } + if (*format == '&') { + format ++; + if (mrb_nil_p(*bp)) { + mrb_raise(mrb, E_ARGUMENT_ERROR, "no block given"); + } + } *p = *bp; } break; -- cgit v1.2.3 From a5ac49de3038955732d9d06271a5df9175e86669 Mon Sep 17 00:00:00 2001 From: dearblue Date: Sun, 4 Mar 2018 23:48:45 +0900 Subject: fix && to &! in mrb_get_args() --- include/mruby.h | 2 +- src/class.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/mruby.h b/include/mruby.h index 8fc2721b1..3e13050b6 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -843,7 +843,7 @@ MRB_API struct RClass * mrb_define_module_under(mrb_state *mrb, struct RClass *o * | `i` | {Integer} | {mrb_int} | | * | `b` | boolean | {mrb_bool} | | * | `n` | {Symbol} | {mrb_sym} | | - * | `&` | block | {mrb_value} | when && gives raised exception if no block given. | + * | `&` | block | {mrb_value} | when &! gives raised exception if no block given. | * | `*` | rest arguments | {mrb_value} *, {mrb_int} | Receive the rest of arguments as an array. | * | | | optional | | After this spec following specs would be optional. | * | `?` | optional given | {mrb_bool} | `TRUE` if preceding argument is given. Used to check optional argument is given. | diff --git a/src/class.c b/src/class.c index e0f8d4673..b01bbc4e8 100644 --- a/src/class.c +++ b/src/class.c @@ -593,7 +593,7 @@ mrb_get_argv(mrb_state *mrb) n: Symbol [mrb_sym] d: Data [void*,mrb_data_type const] 2nd argument will be used to check data type so it won't be modified I: Inline struct [void*] - &: Block [mrb_value] when && gives raised exception if no block given + &: Block [mrb_value] when &! gives raised exception if no block given *: rest argument [mrb_value*,mrb_int] The rest of the arguments as an array; *! avoid copy of the stack |: optional Following arguments are optional ?: optional given [mrb_bool] true if preceding argument (optional) is given @@ -937,7 +937,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) else { bp = mrb->c->stack + mrb->c->ci->argc + 1; } - if (*format == '&') { + if (*format == '!') { format ++; if (mrb_nil_p(*bp)) { mrb_raise(mrb, E_ARGUMENT_ERROR, "no block given"); -- cgit v1.2.3