blob: 0a8002ef807a6eb0c474907a52658a2b666480ff [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001SYNOPSIS
Zesstra715ec202025-07-09 22:18:31 +02002 mixed apply(closure cl, ...)
MG Mud User88f12472016-06-24 23:31:02 +02003
Zesstra715ec202025-07-09 22:18:31 +02004DESCRIPTION
5 Evaluates the closure <cl> with the following arguments.
6 If the last argument is an array or struct, it will be
7 flattened: ie. the array/struct itself will be removed and its
8 contents added to the argument list of <cl>
MG Mud User88f12472016-06-24 23:31:02 +02009
Zesstra715ec202025-07-09 22:18:31 +020010 If <cl> is not a closure, it will simply be returned (and all
11 other arguments are ignored).
MG Mud User88f12472016-06-24 23:31:02 +020012
Zesstra715ec202025-07-09 22:18:31 +020013EXAMPLES
14 The flattening of the last argument is the important difference
15 between apply() and funcall(). For example:
MG Mud User88f12472016-06-24 23:31:02 +020016
Zesstra715ec202025-07-09 22:18:31 +020017 mixed eval(object ob, string func, mixed *args)
18 {
19 return apply(#'call_other, ob, func, args);
20 }
MG Mud User88f12472016-06-24 23:31:02 +020021
Zesstra715ec202025-07-09 22:18:31 +020022 This will result in calling
MG Mud User88f12472016-06-24 23:31:02 +020023
Zesstra715ec202025-07-09 22:18:31 +020024 ob->func(args[0],args[1],...,args[sizeof(args)-1]).
MG Mud User88f12472016-06-24 23:31:02 +020025
Zesstra715ec202025-07-09 22:18:31 +020026 Using funcall() instead of apply() would have given us
MG Mud User88f12472016-06-24 23:31:02 +020027
Zesstra715ec202025-07-09 22:18:31 +020028 ob->func(args).
29
30
31 Of course, with the '...' operator we could also write
32
33 mixed eval(object ob, string func, mixed *args)
34 {
35 return funcall(#'call_other, ob, func, args...);
36 }
37
38 and achieve the same result.
39
40HISTORY
41 Introduced in 3.2@70
42 LDMud 3.2.8 adds the returning of a non-closure as first
43 argument.
44 LDMud 3.3 added the '...' operator and thus made apply() in fact
45 redundant.
46 LDMud 3.3.266 added support for structs.
47
48SEE ALSO
MG Mud User88f12472016-06-24 23:31:02 +020049 funcall(E), closures(LPC), varargs(LPC)