forked from svaarala/duktape
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathduk_call.yaml
More file actions
54 lines (43 loc) · 1.6 KB
/
duk_call.yaml
File metadata and controls
54 lines (43 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
name: duk_call
proto: |
void duk_call(duk_context *ctx, duk_idx_t nargs);
stack: |
[ ... func! arg1! ...! argN! ] -> [ ... retval! ]
summary: |
<p>Call target function <code>func</code> with <code>nargs</code> arguments
(not counting the function itself). The function and its arguments
are replaced by a single return value. An error thrown during the
function call is not automatically caught.
</p>
<p>The target function <code>this</code> binding is initially set to
<code>undefined</code>. If the target function is not strict, the binding
is replaced by the global object before the function is invoked; see
<a href="http://www.ecma-international.org/ecma-262/5.1/#sec-10.4.3">Entering Function Code</a>.
If you want to control the <code>this</code> binding, you can use
<code><a href="#duk_call_method">duk_call_method()</a></code> or
<code><a href="#duk_call_prop">duk_call_prop()</a></code> instead.</p>
<p>This API call is equivalent to:</p>
<pre class="ecmascript-code">
var retval = func(arg1, ..., argN);
</pre>
<p>or:</p>
<pre class="ecmascript-code">
var retval = func.call(undefined, arg1, ..., argN);
</pre>
example: |
/* Assume target function is already on stack at func_idx; the target
* function adds arguments and returns the result.
*/
duk_idx_t func_idx = /* ... */;
duk_dup(ctx, func_idx);
duk_push_int(ctx, 2);
duk_push_int(ctx, 3);
duk_call(ctx, 2); /* [ ... func 2 3 ] -> [ ... 5 ] */
printf("2+3=%ld\n", (long) duk_get_int(ctx, -1));
duk_pop(ctx);
tags:
- call
seealso:
- duk_call_method
- duk_call_prop
introduced: 1.0.0