From d7c09fb24a21aa781861b7ea007773b0788382d7 Mon Sep 17 00:00:00 2001 From: dearblue Date: Sat, 19 Feb 2022 21:55:52 +0900 Subject: [PATCH] Improved documentation for `struct mrb_kwargs` [ci skip] - Changed the description to match the order of the changed members. - Replaced "array of symbols" instead of "array of strings that mean symbols". - The `mrb_kwargs::optional` member has not been present since the first merge. It is a remnant from development time. - Removed `const` modifier used in variable declarations in examples. This is not always necessary from a user perspective. - Added note on the use of `MRB_SYM()`. resolved #5649 --- include/mruby.h | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/include/mruby.h b/include/mruby.h index 3e92021ac..f18fd472b 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -948,14 +948,14 @@ typedef const char *mrb_args_format; /** * Get keyword arguments by `mrb_get_args()` with `:` specifier. * - * `mrb_kwargs::num` indicates that the number of keyword values. + * `mrb_kwargs::num` indicates that the total number of keyword values. * - * `mrb_kwargs::values` is an object array, and the keyword argument corresponding to the string array is assigned. - * Note that `undef` is assigned if there is no keyword argument corresponding to `mrb_kwargs::optional`. + * `mrb_kwargs::required` indicates that the specified number of keywords starting from the beginning of the `mrb_sym` array are required. * - * `mrb_kwargs::table` accepts a string array. + * `mrb_kwargs::table` accepts a `mrb_sym` array of C. * - * `mrb_kwargs::required` indicates that the specified number of keywords starting from the beginning of the string array are required. + * `mrb_kwargs::values` is an object array of C, and the keyword argument corresponding to the `mrb_sym` array is assigned. + * Note that `undef` is assigned if there is no keyword argument corresponding over `mrb_kwargs::required` to `mrb_kwargs::num`. * * `mrb_kwargs::rest` is the remaining keyword argument that can be accepted as `**rest` in Ruby. * If `NULL` is specified, `ArgumentError` is raised when there is an undefined keyword. @@ -965,10 +965,10 @@ typedef const char *mrb_args_format; * // def method(a: 1, b: 2) * * uint32_t kw_num = 2; - * const char *kw_names[kw_num] = { "a", "b" }; * uint32_t kw_required = 0; + * mrb_sym kw_names[] = { mrb_intern_lit(mrb, "a"), mrb_intern_lit(mrb, "b") }; * mrb_value kw_values[kw_num]; - * const mrb_kwargs kwargs = { kw_num, kw_required, kw_names, kw_values, NULL }; + * mrb_kwargs kwargs = { kw_num, kw_required, kw_names, kw_values, NULL }; * * mrb_get_args(mrb, ":", &kwargs); * if (mrb_undef_p(kw_values[0])) { kw_values[0] = mrb_fixnum_value(1); } @@ -979,10 +979,12 @@ typedef const char *mrb_args_format; * * mrb_value str, kw_rest; * uint32_t kw_num = 3; - * const mrb_sym kw_names[kw_num] = { MRB_SYM(x), MRB_SYM(y), MRB_SYM(z) }; * uint32_t kw_required = 1; + * // Note that `#include ` is required beforehand because `MRB_SYM()` is used. + * // If the usage of `MRB_SYM()` is not desired, replace it with `mrb_intern_lit()`. + * mrb_sym kw_names[] = { MRB_SYM(x), MRB_SYM(y), MRB_SYM(z) }; * mrb_value kw_values[kw_num]; - * const mrb_kwargs kwargs = { kw_num, kw_required, kw_names, kw_values, &kw_rest }; + * mrb_kwargs kwargs = { kw_num, kw_required, kw_names, kw_values, &kw_rest }; * * mrb_get_args(mrb, "S:", &str, &kwargs); * // or: mrb_get_args(mrb, ":S", &kwargs, &str);