mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge pull request #5653 from dearblue/doc-keywords
Improved documentation for `struct mrb_kwargs` [ci skip]
This commit is contained in:
+11
-9
@@ -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 <mruby/presym.h>` 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);
|
||||
|
||||
Reference in New Issue
Block a user