Ruby
3.4.0dev (2024-12-06 revision 892c46283a5ea4179500d951c9d4866c0051f27b)
|
Declares rb_define_variable(). More...
#include "ruby/internal/dllexport.h"
#include "ruby/internal/value.h"
#include "ruby/internal/attr/nonnull.h"
#include "ruby/internal/attr/noreturn.h"
Go to the source code of this file.
Typedefs | |
typedef VALUE | rb_gvar_getter_t(ID id, VALUE *data) |
Type that represents a global variable getter function. More... | |
typedef void | rb_gvar_setter_t(VALUE val, ID id, VALUE *data) |
Type that represents a global variable setter function. More... | |
typedef void | rb_gvar_marker_t(VALUE *var) |
Type that represents a global variable marker function. More... | |
Functions | |
void | rb_define_variable (const char *name, VALUE *var) |
"Shares" a global variable between Ruby and C. More... | |
void | rb_define_virtual_variable (const char *name, rb_gvar_getter_t *getter, rb_gvar_setter_t *setter) |
Defines a global variable that is purely function-backended. More... | |
void | rb_define_hooked_variable (const char *name, VALUE *var, rb_gvar_getter_t *getter, rb_gvar_setter_t *setter) |
Identical to rb_define_virtual_variable(), but can also specify a storage. More... | |
void | rb_define_readonly_variable (const char *name, const VALUE *var) |
Identical to rb_define_variable(), except it does not allow Ruby programs to assign values to such global variable. More... | |
void | rb_define_const (VALUE klass, const char *name, VALUE val) |
Defines a Ruby level constant under a namespace. More... | |
void | rb_define_global_const (const char *name, VALUE val) |
Identical to rb_define_const(), except it defines that of "global", i.e. More... | |
void | rb_deprecate_constant (VALUE mod, const char *name) |
Asserts that the given constant is deprecated. More... | |
VALUE | rb_gv_set (const char *name, VALUE val) |
Assigns to a global variable. More... | |
VALUE | rb_gv_get (const char *name) |
Obtains a global variable. More... | |
VALUE | rb_iv_get (VALUE obj, const char *name) |
Obtains an instance variable. More... | |
VALUE | rb_iv_set (VALUE obj, const char *name, VALUE val) |
Assigns to an instance variable. More... | |
Variables | |
rb_gvar_getter_t | rb_gvar_undef_getter |
rb_gvar_setter_t | rb_gvar_undef_setter |
rb_gvar_marker_t | rb_gvar_undef_marker |
rb_gvar_getter_t | rb_gvar_val_getter |
This is the getter function that backs global variables defined from a ruby script. More... | |
rb_gvar_setter_t | rb_gvar_val_setter |
This is the setter function that backs global variables defined from a ruby script. More... | |
rb_gvar_marker_t | rb_gvar_val_marker |
This is the setter function that backs global variables defined from a ruby script. More... | |
rb_gvar_getter_t | rb_gvar_var_getter |
rb_gvar_setter_t | rb_gvar_var_setter |
rb_gvar_marker_t | rb_gvar_var_marker |
rb_gvar_setter_t | rb_gvar_readonly_setter |
This function just raises rb_eNameError. More... | |
Declares rb_define_variable().
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 variable.h.
Type that represents a global variable getter function.
[in] | id | The variable name. |
[in,out] | data | Where the value is stored. |
Definition at line 37 of file variable.h.
typedef void rb_gvar_marker_t(VALUE *var) |
Type that represents a global variable marker function.
[in] | var | Where the value is to be stored. |
Definition at line 53 of file variable.h.
Type that represents a global variable setter function.
[in] | val | The value to set. |
[in] | id | The variable name. |
[in,out] | data | Where the value is to be stored. |
Definition at line 46 of file variable.h.
Defines a Ruby level constant under a namespace.
[out] | klass | Namespace for the constant to reside. |
[in] | name | Name of the constant. |
[in] | val | Value of the constant. |
rb_eTypeError | klass is not a kind of rb_cModule. |
rb_eFrozenError | klass is frozen. |
klass::name
is defined to be val
. name
). Definition at line 3726 of file variable.c.
Referenced by rb_define_global_const().
void rb_define_global_const | ( | const char * | name, |
VALUE | val | ||
) |
Identical to rb_define_const(), except it defines that of "global", i.e.
toplevel constant.
[in] | name | Name of the constant. |
[in] | val | Value of the constant. |
rb_eFrozenError | rb_cObject is frozen. |
val
. name
). Definition at line 3740 of file variable.c.
Referenced by ruby_prog_init().
void rb_define_hooked_variable | ( | const char * | name, |
VALUE * | var, | ||
rb_gvar_getter_t * | getter, | ||
rb_gvar_setter_t * | setter | ||
) |
Identical to rb_define_virtual_variable(), but can also specify a storage.
A programmer can use the storage for e.g. memoisation, storing intermediate computation result, etc.
Also you can pass 0 to this function, unlike other variants:
*NULL
, and just causes SEGV.[in] | name | Variable name, in C's string. |
[in] | var | Variable storage. |
[in] | getter | A getter function. |
[in] | setter | A setter function. |
name
is defined if absent. Definition at line 719 of file variable.c.
Referenced by rb_define_readonly_variable(), rb_define_variable(), rb_define_virtual_variable(), and ruby_prog_init().
void rb_define_readonly_variable | ( | const char * | name, |
const VALUE * | var | ||
) |
Identical to rb_define_variable(), except it does not allow Ruby programs to assign values to such global variable.
C codes can still set values at will. This could be handy for you when implementing an errno
-like experience, where a method updates a read-only global variable as a side- effect.
[in] | name | Variable (Ruby side). |
[in] | var | Variable (C side). |
name
is defined if absent, and its storage is set to var
. Definition at line 744 of file variable.c.
void rb_define_variable | ( | const char * | name, |
VALUE * | var | ||
) |
"Shares" a global variable between Ruby and C.
Normally a Ruby-level global variable is stored somewhere deep inside of the interpreter's execution context, but this way you can explicitly specify its storage.
In the above example a Ruby global variable named $foo
is stored in a C global variable named foo
.
[in] | name | Variable (Ruby side). |
[in] | var | Variable (C side). |
name
is defined if absent, and its storage is set to var
. Definition at line 738 of file variable.c.
void rb_define_virtual_variable | ( | const char * | name, |
rb_gvar_getter_t * | getter, | ||
rb_gvar_setter_t * | setter | ||
) |
Defines a global variable that is purely function-backended.
By using this API a programmer can define a global variable that dynamically changes from time to time.
[in] | name | Variable name, in C's string. |
[in] | getter | A getter function. |
[in] | setter | A setter function. |
name
is defined if absent. Definition at line 750 of file variable.c.
Referenced by ruby_prog_init().
void rb_deprecate_constant | ( | VALUE | mod, |
const char * | name | ||
) |
Asserts that the given constant is deprecated.
Attempt to refer such constant will produce a warning.
[in] | mod | Namespace of the target constant. |
[in] | name | Name of the constant. |
rb_eNameError | No such constant. |
rb_eFrozenError | mod is frozen. |
name
under mod
is deprecated. Definition at line 3788 of file variable.c.
VALUE rb_gv_get | ( | const char * | name | ) |
Obtains a global variable.
[in] | name | Global variable to query. |
RUBY_Qnil | The global variable does not exist. |
otherwise | The value assigned to the global variable. |
Definition at line 925 of file variable.c.
Assigns to a global variable.
[in] | name | Target global variable. |
[in] | val | Value to assign. |
name
is defined if absent, whose value is set to val
. Definition at line 911 of file variable.c.
Obtains an instance variable.
[in] | obj | Target object. |
[in] | name | Target instance variable to query. |
rb_eEncodingError | name is corrupt (contains Hanzi etc.). |
RUBY_nil | No such instance variable. |
otherwise | The value assigned to the instance variable. |
Definition at line 4213 of file variable.c.
Assigns to an instance variable.
[out] | obj | Target object. |
[in] | name | Target instance variable. |
[in] | val | Value to assign. |
rb_eFrozenError | Can't modify obj . |
rb_eArgError | obj has too many instance variables. |
name
is defined if absent on obj
, whose value is set to val
. Definition at line 4224 of file variable.c.
rb_gvar_setter_t rb_gvar_readonly_setter |
This function just raises rb_eNameError.
Handy when you want to prohibit a global variable from being squashed by someone.
Definition at line 135 of file variable.h.
Referenced by rb_define_readonly_variable(), rb_define_virtual_variable(), and ruby_prog_init().
rb_gvar_getter_t rb_gvar_undef_getter |
This function has no actual usage (than in ruby itself). Please ignore. It was a bad idea to expose this function to 3rd parties, but we can no longer delete it.
Definition at line 62 of file variable.h.
rb_gvar_marker_t rb_gvar_undef_marker |
This function has no actual usage (than in ruby itself). Please ignore. It was a bad idea to expose this function to 3rd parties, but we can no longer delete it.
Definition at line 80 of file variable.h.
rb_gvar_setter_t rb_gvar_undef_setter |
This function has no actual usage (than in ruby itself). Please ignore. It was a bad idea to expose this function to 3rd parties, but we can no longer delete it.
Definition at line 71 of file variable.h.
rb_gvar_getter_t rb_gvar_val_getter |
This is the getter function that backs global variables defined from a ruby script.
Extension libraries can use this if its global variable needs no custom logic.
Definition at line 87 of file variable.h.
Referenced by rb_define_virtual_variable().
rb_gvar_marker_t rb_gvar_val_marker |
This is the setter function that backs global variables defined from a ruby script.
Extension libraries can use this if its global variable needs no custom logic.
Definition at line 101 of file variable.h.
rb_gvar_setter_t rb_gvar_val_setter |
This is the setter function that backs global variables defined from a ruby script.
Extension libraries can use this if its global variable needs no custom logic.
Definition at line 94 of file variable.h.
rb_gvar_getter_t rb_gvar_var_getter |
This function has no actual usage (than in ruby itself). Please ignore. It was a bad idea to expose this function to 3rd parties, but we can no longer delete it.
Definition at line 110 of file variable.h.
Referenced by rb_define_hooked_variable().
rb_gvar_marker_t rb_gvar_var_marker |
This function has no actual usage (than in ruby itself). Please ignore. It was a bad idea to expose this function to 3rd parties, but we can no longer delete it.
Definition at line 128 of file variable.h.
Referenced by rb_define_hooked_variable().
rb_gvar_setter_t rb_gvar_var_setter |
This function has no actual usage (than in ruby itself). Please ignore. It was a bad idea to expose this function to 3rd parties, but we can no longer delete it.
Definition at line 119 of file variable.h.
Referenced by rb_define_hooked_variable().