blob: e5b0bfa920143a53ed74e5b14c4407e69095a71f [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001SYNOPSIS
2 mixed to_struct(mixed *|mapping data)
3 mixed to_struct(mixed *|mapping data, struct template)
4 mixed to_struct(struct data)
5 mixed to_struct(struct data, struct template)
6
7DESCRIPTION
8 The given array, mapping or struct <data> is returned as a struct.
9 If a <template> struct is given, the returned struct is of the same
10 type. Without a template, an anonymous struct is returned in case of
11 arrays and mappings and in case of structs <data> is returned
12 unchanged.
13
14 If <data> is an array, its elements are assigned in order to the
15 resulting struct. For an anonymous struct, all elements of <data>
16 are assigned, for a templated struct only as many as fit into
17 the struct.
18
19 If <data> is a mapping and no template is given, the resulting
20 anonymous struct contains all elements from <data> with a string
21 key; the key name is used as struct member name.
22
23 If <data> is a mapping and a template is given, the struct
24 member names are used as keys for lookups in <data>; the found
25 data is assigned to the struct members.
26
27 If <data> is a struct and a template is given, a struct of the type
28 of template is created and all members from <data> are copied to the
29 new struct, which exist in both structs. This conversion is only
30 allowed between a struct and one of its base structs or a base struct
31 and one of its children. Otherwise an error is raised.
32
33 Neither <data> nor <template> will be changed in this process - the
34 result is a new struct value. The actual value of <template> does not
35 matter, only its type.
36
37 Since the returned struct can't be known at compile time, the
38 efun is declared to return 'mixed'.
39
40HISTORY
41 Introduced in LDMud 3.3.250 .
42 LDMud 3.3.344 added the template argument.
43 LDMud 3.3.433 added the conversion from mappings.
44 LDMud 3.3.720 added the conversion of structs into another struct.
45
46SEE ALSO
47 to_array(E), to_string(E), mkmapping(E), structs(LPC)