Ruby
3.4.0dev (2024-11-05 revision 348a53415339076afc4a02fcd09f3ae36e9c4c61)
|
Public APIs related to rb_cStruct. More...
#include "ruby/internal/attr/nonnull.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/intern/vm.h"
#include "ruby/internal/value.h"
Go to the source code of this file.
Functions | |
VALUE | rb_struct_new (VALUE klass,...) |
Creates an instance of the given struct. More... | |
VALUE | rb_struct_define (const char *name,...) |
Defines a struct class. More... | |
VALUE | rb_struct_define_under (VALUE space, const char *name,...) |
Identical to rb_struct_define(), except it defines the class under the specified namespace instead of global toplevel. More... | |
VALUE | rb_struct_alloc (VALUE klass, VALUE values) |
Identical to rb_struct_new(), except it takes the field values as a Ruby array. More... | |
VALUE | rb_struct_initialize (VALUE self, VALUE values) |
Mass-assigns a struct's fields. More... | |
VALUE | rb_struct_getmember (VALUE self, ID key) |
Identical to rb_struct_aref(), except it takes ID instead of VALUE. More... | |
VALUE | rb_struct_s_members (VALUE klass) |
Queries the list of the names of the fields of the given struct class. More... | |
VALUE | rb_struct_members (VALUE self) |
Queries the list of the names of the fields of the class of the given struct object. More... | |
VALUE | rb_struct_alloc_noinit (VALUE klass) |
Allocates an instance of the given class. More... | |
VALUE | rb_struct_define_without_accessor (const char *name, VALUE super, rb_alloc_func_t func,...) |
Identical to rb_struct_define(), except it does not define accessor methods. More... | |
VALUE | rb_struct_define_without_accessor_under (VALUE outer, const char *class_name, VALUE super, rb_alloc_func_t alloc,...) |
Identical to rb_struct_define_without_accessor(), except it defines the class under the specified namespace instead of global toplevel. More... | |
VALUE | rb_data_define (VALUE super,...) |
Defines an anonymous data class. More... | |
Public APIs related to rb_cStruct.
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 struct.h.
Defines an anonymous data class.
[in] | super | Superclass of the defining class. Must be a descendant of ::rb_cData, or 0 as ::rb_cData. |
[in] | ... | Arbitrary number of const char* , terminated by NULL. Each of which are the name of fields. |
rb_eArgError | Duplicated field name. |
Identical to rb_struct_new(), except it takes the field values as a Ruby array.
[in] | klass | The class of the instance to allocate. |
[in] | values | Field values. |
klass
. klass
must be a subclass of rb_cStruct. values
must be an instance of struct RArray. Allocates an instance of the given class.
This consequential name is of course because rb_struct_alloc() not only allocates but also initialises an instance. The API design is broken.
[in] | klass | A subclass of rb_cStruct. |
klass
, not initialised. VALUE rb_struct_define | ( | const char * | name, |
... | |||
) |
Defines a struct class.
[in] | name | Name of the class. |
[in] | ... | Arbitrary number of const char* , terminated by NULL. Each of which are the name of fields. |
rb_eNameError | name is not a constant name. |
rb_eTypeError | name is already taken. |
rb_eArgError | Duplicated field name. |
name
is defined. name
is allowed to be a null pointer. This function creates an anonymous struct class then. Identical to rb_struct_define(), except it defines the class under the specified namespace instead of global toplevel.
[out] | space | Namespace that the defining class shall reside. |
[in] | name | Name of the class. |
[in] | ... | Arbitrary number of const char* , terminated by NULL. Each of which are the name of fields. |
rb_eNameError | name is not a constant name. |
rb_eTypeError | name is already taken. |
rb_eArgError | Duplicated field name. |
name
is a constant under space
. VALUE rb_struct_define_without_accessor | ( | const char * | name, |
VALUE | super, | ||
rb_alloc_func_t | func, | ||
... | |||
) |
Identical to rb_struct_define(), except it does not define accessor methods.
You have to define them yourself. Forget about the allocator function parameter; it is for internal use only. Extension libraries are unable to properly allocate a ruby struct, because RStruct
is opaque.
[in] | name | Name of the class. |
[in] | super | Superclass of the defining class. |
[in] | func | Must be 0 for extension libraries. |
[in] | ... | Arbitrary number of const char* , terminated by NULL. Each of which are the name of fields. |
rb_eNameError | name is not a constant name. |
rb_eTypeError | name is already taken. |
rb_eArgError | Duplicated field name. |
name
is defined. name
is allowed to be a null pointer. This function creates an anonymous struct class then. VALUE rb_struct_define_without_accessor_under | ( | VALUE | outer, |
const char * | class_name, | ||
VALUE | super, | ||
rb_alloc_func_t | alloc, | ||
... | |||
) |
Identical to rb_struct_define_without_accessor(), except it defines the class under the specified namespace instead of global toplevel.
It can also be seen as a routine identical to rb_struct_define_under(), except it does not define accessor methods.
[out] | outer | Namespace that the defining class shall reside. |
[in] | class_name | Name of the class. |
[in] | super | Superclass of the defining class. |
[in] | alloc | Must be 0 for extension libraries. |
[in] | ... | Arbitrary number of const char* , terminated by NULL. Each of which are the name of fields. |
rb_eNameError | class_name is not a constant name. |
rb_eTypeError | class_name is already taken. |
rb_eArgError | Duplicated field name. |
class_name
is a constant under outer
. Identical to rb_struct_aref(), except it takes ID instead of VALUE.
[in] | self | An instance of a struct class. |
[in] | key | Key to query. |
rb_eTypeError | self is not a struct. |
rb_eNameError | No such field. |
key
in self
. Queries the list of the names of the fields of the class of the given struct object.
This is almost the same as calling rb_struct_s_members() over the class of the receiver.
[in] | self | An instance of a subclass of rb_cStruct. |
Creates an instance of the given struct.
[in] | klass | The class of the instance to allocate. |
[in] | ... | The fields. |
klass
. klass
must be a subclass of rb_cStruct. Queries the list of the names of the fields of the given struct class.
[in] | klass | A subclass of rb_cStruct. |
klass
. Definition at line 67 of file struct.c.
Referenced by rb_struct_members().