Ruby
3.4.0dev (2024-11-22 revision 37a72b0150ec36b4ea27175039afc28c62207b0c)
|
Public APIs related to rb_cProc. More...
#include "ruby/internal/dllexport.h"
#include "ruby/internal/iterator.h"
#include "ruby/internal/value.h"
Go to the source code of this file.
Functions | |
VALUE | rb_block_proc (void) |
Constructs a Proc object from implicitly passed components. More... | |
VALUE | rb_block_lambda (void) |
Identical to rb_proc_new(), except it returns a lambda. More... | |
VALUE | rb_proc_new (rb_block_call_func_t func, VALUE callback_arg) |
This is an rb_iterate() + rb_block_proc() combo. More... | |
VALUE | rb_obj_is_proc (VALUE recv) |
Queries if the given object is a proc. More... | |
VALUE | rb_proc_call (VALUE recv, VALUE args) |
Evaluates the passed proc with the passed arguments. More... | |
VALUE | rb_proc_call_kw (VALUE recv, VALUE args, int kw_splat) |
Identical to rb_proc_call(), except you can specify how to handle the last element of the given array. More... | |
VALUE | rb_proc_call_with_block (VALUE recv, int argc, const VALUE *argv, VALUE proc) |
Identical to rb_proc_call(), except you can additionally pass another proc object, as a block. More... | |
VALUE | rb_proc_call_with_block_kw (VALUE recv, int argc, const VALUE *argv, VALUE proc, int kw_splat) |
Identical to rb_proc_call_with_block(), except you can specify how to handle the last element of the given array. More... | |
int | rb_proc_arity (VALUE recv) |
Queries the number of mandatory arguments of the given Proc. More... | |
VALUE | rb_proc_lambda_p (VALUE recv) |
Queries if the given object is a lambda. More... | |
VALUE | rb_binding_new (void) |
Snapshots the current execution context and turn it into an instance of rb_cBinding. More... | |
VALUE | rb_obj_method (VALUE recv, VALUE mid) |
Creates a method object. More... | |
VALUE | rb_obj_is_method (VALUE recv) |
Queries if the given object is a method. More... | |
VALUE | rb_method_call (int argc, const VALUE *argv, VALUE recv) |
Evaluates the passed method with the passed arguments. More... | |
VALUE | rb_method_call_kw (int argc, const VALUE *argv, VALUE recv, int kw_splat) |
Identical to rb_method_call(), except you can specify how to handle the last element of the given array. More... | |
VALUE | rb_method_call_with_block (int argc, const VALUE *argv, VALUE recv, VALUE proc) |
Identical to rb_proc_call(), except you can additionally pass a proc as a block. More... | |
VALUE | rb_method_call_with_block_kw (int argc, const VALUE *argv, VALUE recv, VALUE proc, int kw_splat) |
Identical to rb_method_call_with_block(), except you can specify how to handle the last element of the given array. More... | |
int | rb_mod_method_arity (VALUE mod, ID mid) |
Queries the number of mandatory arguments of the method defined in the given module. More... | |
int | rb_obj_method_arity (VALUE obj, ID mid) |
Identical to rb_mod_method_arity(), except it searches for singleton methods rather than instance methods. More... | |
VALUE | rb_protect (VALUE(*func)(VALUE args), VALUE args, int *state) |
Protects a function call from potential global escapes from the function. More... | |
Public APIs related to rb_cProc.
RBIMPL
or rbimpl
are implementation details. Don't take them as canon. They could rapidly appear then vanish. The name (path) of this header file is also an implementation detail. Do not expect it to persist at the place it is now. Developers are free to move it anywhere anytime at will. __VA_ARGS__
is always available. We assume C99 for ruby itself but we don't assume languages of extension libraries. They could be written in C++98. Definition in file proc.h.
VALUE rb_binding_new | ( | void | ) |
Snapshots the current execution context and turn it into an instance of rb_cBinding.
VALUE rb_block_lambda | ( | void | ) |
Identical to rb_proc_new(), except it returns a lambda.
rb_eArgError | There is no passed block. |
VALUE rb_block_proc | ( | void | ) |
Constructs a Proc object from implicitly passed components.
When a ruby method is called with a block, that block is not explicitly passed around using C level function parameters. This function gathers all the necessary info to turn them into a Ruby level instance of rb_cProc.
rb_eArgError | There is no passed block. |
Definition at line 813 of file proc.c.
Referenced by rb_f_trace_var(), rb_method_call(), and rb_method_call_kw().
Evaluates the passed method with the passed arguments.
[in] | argc | Number of objects of argv . |
[in] | argv | Arbitrary number of method arguments. |
[in] | recv | The method object to call. |
rb_eTypeError | recv is not a method. |
rb_eException | Any exceptions happen inside. |
Identical to rb_method_call(), except you can specify how to handle the last element of the given array.
[in] | argc | Number of objects of argv . |
[in] | argv | Arbitrary number of method arguments. |
[in] | recv | The method object to call. |
[in] | kw_splat | Handling of keyword parameters:
|
rb_eTypeError | recv is not a method. |
rb_eException | Any exceptions happen inside. |
Identical to rb_proc_call(), except you can additionally pass a proc as a block.
[in] | argc | Number of objects of argv . |
[in] | argv | Arbitrary number of method arguments. |
[in] | recv | The method object to call. |
[in] | proc | Proc as a passed block. |
rb_eTypeError | recv is not a method. |
rb_eException | Any exceptions happen inside. |
Definition at line 2524 of file proc.c.
Referenced by rb_method_call().
VALUE rb_method_call_with_block_kw | ( | int | argc, |
const VALUE * | argv, | ||
VALUE | recv, | ||
VALUE | proc, | ||
int | kw_splat | ||
) |
Identical to rb_method_call_with_block(), except you can specify how to handle the last element of the given array.
It can also be seen as a routine identical to rb_method_call_kw(), except you can additionally pass another proc object as a block.
[in] | argc | Number of objects of argv . |
[in] | argv | Arbitrary number of method arguments. |
[in] | recv | The method object to call. |
[in] | proc | Proc as a passed block. |
[in] | kw_splat | Handling of keyword parameters:
|
rb_eTypeError | recv is not a method. |
rb_eException | Any exceptions happen inside. |
Definition at line 2511 of file proc.c.
Referenced by rb_method_call_kw(), and rb_method_call_with_block().
Queries the number of mandatory arguments of the method defined in the given module.
If it is declared to take no arguments, returns 0
. If it takes exactly n
arguments, returns n
. If it has optional arguments, returns -n-1
, where n
is the number of mandatory arguments. Keyword arguments will be considered as a single additional argument, that argument being mandatory if any keyword argument is mandatory.
[in] | mod | Namespace to search a method for. |
[in] | mid | Method id. |
0 | It takes no arguments. |
>0 | It takes exactly this number of arguments. |
<0 | It takes optional arguments. |
Definition at line 2892 of file proc.c.
Referenced by rb_obj_method_arity().
Queries if the given object is a method.
[in] | recv | Object in question. |
RUBY_Qtrue | It is a method. |
RUBY_Qfalse | Otherwise. |
Definition at line 1610 of file proc.c.
Referenced by rb_econv_prepare_options().
Queries if the given object is a proc.
[in] | recv | Object in question. |
RUBY_Qtrue | It is a proc. |
RUBY_Qfalse | Otherwise. |
Definition at line 119 of file proc.c.
Referenced by rb_econv_prepare_options().
Creates a method object.
A method object is a proc-like object that you can "call". Note that a method object snapshots the method at the time the object is created:
[in] | recv | Receiver of the method. |
[in] | mid | Method name, in either String or Symbol. |
rb_eNoMethodError | No such method. |
Identical to rb_mod_method_arity(), except it searches for singleton methods rather than instance methods.
[in] | obj | Object to search for a singleton method. |
[in] | mid | Method id. |
0 | It takes no arguments. |
>0 | It takes exactly this number of arguments. |
<0 | It takes optional arguments. |
int rb_proc_arity | ( | VALUE | recv | ) |
Queries the number of mandatory arguments of the given Proc.
If its block is declared to take no arguments, returns 0
. If the block is known to take exactly n
arguments, returns n
. If the block has optional arguments, returns -n-1
, where n
is the number of mandatory arguments, with the exception for blocks that are not lambdas and have only a finite number of optional arguments; in this latter case, returns n
. Keyword arguments will be considered as a single additional argument, that argument being mandatory if any keyword argument is mandatory.
[in] | recv | Target Proc object. |
0 | It takes no arguments. |
>0 | It takes exactly this number of arguments. |
<0 | It takes optional arguments. |
Identical to rb_proc_call(), except you can specify how to handle the last element of the given array.
[in] | recv | The proc to call. |
[in] | args | An instance of RArray which is the arguments. |
[in] | kw_splat | Handling of keyword parameters:
|
rb_eException | Any exceptions happen inside. |
Definition at line 956 of file proc.c.
Referenced by rb_proc_call().
Identical to rb_proc_call(), except you can additionally pass another proc object, as a block.
Nowadays procs can take blocks:
And this function is to pass one to such procs.
[in] | recv | The proc to call. |
[in] | argc | Number of arguments. |
[in] | argv | Arbitrary number of proc arguments. |
[in] | proc | Proc as a passed block. |
rb_eException | Any exceptions happen inside. |
VALUE rb_proc_call_with_block_kw | ( | VALUE | recv, |
int | argc, | ||
const VALUE * | argv, | ||
VALUE | proc, | ||
int | kw_splat | ||
) |
Identical to rb_proc_call_with_block(), except you can specify how to handle the last element of the given array.
It can also be seen as a routine identical to rb_proc_call_kw(), except you can additionally pass another proc object as a block.
[in] | recv | The proc to call. |
[in] | argc | Number of arguments. |
[in] | argv | Arbitrary number of proc arguments. |
[in] | proc | Proc as a passed block. |
[in] | kw_splat | Handling of keyword parameters:
|
rb_eException | Any exceptions happen inside. |
Definition at line 983 of file proc.c.
Referenced by rb_proc_call_with_block().
Queries if the given object is a lambda.
Instances of rb_cProc are either lambda or proc. They differ in several points. This function can distinguish them without actually evaluating their contents.
[in] | recv | Target proc object. |
RUBY_Qtrue | It is a lambda. |
RUBY_Qfalse | Otherwise. |
VALUE rb_proc_new | ( | rb_block_call_func_t | func, |
VALUE | callback_arg | ||
) |
This is an rb_iterate() + rb_block_proc() combo.
[in] | func | A backend function of a proc. |
[in] | callback_arg | Passed to func 's callback_arg. |
Definition at line 3332 of file proc.c.
Referenced by rb_fiber_new_storage(), rb_fiber_scheduler_blocking_operation_wait(), and ruby::backward::cxxanyargs::rb_proc_new().
Protects a function call from potential global escapes from the function.
Such global escapes include exceptions, throw
, break
, for example.
It first calls the function func with args
as the argument. If no global escape occurred during the function, it returns the result and *state
is zero. Otherwise, it returns RUBY_Qnil and sets *state
to nonzero. If state
is NULL
, it is not set in both cases.
[in] | func | A function that potentially escapes globally. |
[in] | args | Passed as-is to func . |
[out] | state | State of execution. |
func
returns, or an undefined value when it did not return. *state
is set to zero if succeeded. Nonzero otherwise. rb_set_errinfo(Qnil)
if you decide to ignore the caught exception. Referenced by rb_eval_string_protect(), rb_eval_string_wrap(), rb_f_exec(), and rb_io_open_descriptor().