mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
allow '!' after 'S' specifier of mrb_get_args() that allow nil.
thus "S!" means String|nil type. you have to check nil before dereferencing the value. this is added to address #2882 while keeping code simplicity. besides that current #2882 fix lose polymorphism provided by mrb_get_args().
This commit is contained in:
+9
-1
@@ -435,7 +435,7 @@ to_sym(mrb_state *mrb, mrb_value ss)
|
||||
----------------------------------------------------------------------------------------------
|
||||
o: Object [mrb_value]
|
||||
C: class/module [mrb_value]
|
||||
S: String [mrb_value]
|
||||
S: String [mrb_value] when ! follows the value may be nil
|
||||
A: Array [mrb_value]
|
||||
H: Hash [mrb_value]
|
||||
s: String [char*,mrb_int] Receive two arguments.
|
||||
@@ -525,6 +525,14 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
|
||||
mrb_value *p;
|
||||
|
||||
p = va_arg(ap, mrb_value*);
|
||||
if (*format == '!') {
|
||||
format++;
|
||||
if (mrb_nil_p(*sp)) {
|
||||
*p = *sp++;
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i < argc) {
|
||||
*p = to_str(mrb, *sp++);
|
||||
i++;
|
||||
|
||||
Reference in New Issue
Block a user