summaryrefslogtreecommitdiffhomepage
path: root/include/mruby.h
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2020-06-20 12:49:46 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2020-06-20 12:49:46 +0900
commit49ae2a69f2c3acbb952406768320401cf1769425 (patch)
treefd0b49d898327a1de29e143fb2c68e6991cf710d /include/mruby.h
parent2ffb77586a8ce6f325d2981e2ad88cc9e62ae39b (diff)
downloadmruby-49ae2a69f2c3acbb952406768320401cf1769425.tar.gz
mruby-49ae2a69f2c3acbb952406768320401cf1769425.zip
Add `mrb_get_arg1()` that retrieves single (and only) argument.
`mrb_get_arg1()` raises `ArgumentError` if the method does not receive one argument. And replaces all `mrb_get_args(mrb, "o", &arg)` by the new function.
Diffstat (limited to 'include/mruby.h')
-rw-r--r--include/mruby.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/include/mruby.h b/include/mruby.h
index fef4a0d47..5aba2934a 100644
--- a/include/mruby.h
+++ b/include/mruby.h
@@ -959,8 +959,21 @@ mrb_get_mid(mrb_state *mrb) /* get method symbol */
*/
MRB_API mrb_int mrb_get_argc(mrb_state *mrb);
+/**
+ * Retrieve an array of arguments from mrb_state.
+ *
+ * Correctly handles *splat arguments.
+ */
MRB_API mrb_value* mrb_get_argv(mrb_state *mrb);
+/**
+ * Retrieve the first and only argument from mrb_state.
+ * Raises ArgumentError unless the number of arguments is exactly one.
+ *
+ * Correctly handles *splat arguments.
+ */
+MRB_API mrb_value mrb_get_arg1(mrb_state *mrb);
+
/* `strlen` for character string literals (use with caution or `strlen` instead)
Adjacent string literals are concatenated in C/C++ in translation phase 6.
If `lit` is not one, the compiler will report a syntax error: