Push the values of a structure's fields onto the stack
Integer_Type num = _push_struct_field_values (Struct_Type s)
The _push_struct_field_values
function pushes the values of
all the fields of a structure onto the stack, returning the
number of items pushed. The fields are pushed such that the last
field of the structure is pushed first.
get_struct_field_names, get_struct_field
Get the value associated with a structure field
x = get_struct_field (Struct_Type s, String field_name)
The get_struct_field
function gets the value of the field
whose name is specified by field_name
of the structure s
.
The following example illustrates how this function may be used to to print the value of a structure.
define print_struct (s)
{
variable name;
foreach (get_struct_field_names (s))
{
name = ();
value = get_struct_field (s, name);
vmessage ("s.%s = %s\n", name, string(value));
}
}
set_struct_field, get_struct_field_names, array_info
Retrieve the field names associated with a structure
String_Type[] = get_struct_field_names (Struct_Type s)
The get_struct_field_names
function returns an array of
strings whose elements specify the names of the fields of the
struct s
.
The following example illustrates how the
get_struct_field_names
function may be used to print the
value of a structure.
define print_struct (s)
{
variable name, value;
foreach (get_struct_field_names (s))
{
name = ();
value = get_struct_field (name);
vmessage ("s.%s = %s\n", name, string (value));
}
}
_push_struct_field_values, get_struct_field
Determine whether or not an object is a structure
Integer_Type is_struct_type (X)
The is_struct_type
function returns 1
if the the parameter
refers to a structure or a user-defined type. If the object is
neither, 0
will be returned.
typeof, _typeof
Set the value associated with a structure field
set_struct_field (s, field_name, field_value)
Struct_Type s;
String_Type field_name;
Generic_Type field_value;
The set_struct_field
function sets the value of the field
whose name is specified by field_name
of the structure
s
to field_value
.
get_struct_field, get_struct_field_names, set_struct_fields, array_info
Set the fields of a structure
set_struct_fields (Struct_Type s, ...)
The set_struct_fields
function may be used to set zero or more
fields of a structure. The fields are set in the order in which
they were created when the structure was defined.
variable s = struct { "name", "age", "height" };
set_struct_fields (s, "Bill", 13, 64);
set_struct_field, get_struct_field_names