mirror of https://github.com/svaarala/duktape.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.1 KiB
46 lines
1.1 KiB
=proto
|
|
duk_context *duk_get_context(duk_context *ctx, duk_idx_t index);
|
|
|
|
=stack
|
|
[ ... val! ... ]
|
|
|
|
=summary
|
|
<p>Get a context pointer for a Duktape thread at <code>index</code>. If the
|
|
value at <code>index</code> is not a Duktape thread or the index is invalid,
|
|
returns <code>NULL</code>.</p>
|
|
|
|
<p>The returned context pointer is only valid while the Duktape thread
|
|
is reachable from a garbage collection point of view.</p>
|
|
|
|
<p>If you prefer an error to be thrown for an invalid value or index,
|
|
use <code><a href="#duk_require_context">duk_require_context()</a></code>.</p>
|
|
|
|
=example
|
|
duk_context *new_ctx;
|
|
|
|
/* Create a new thread and get a context pointer. */
|
|
|
|
(void) duk_push_thread(ctx);
|
|
new_ctx = duk_get_context(ctx, -1);
|
|
|
|
/* You can use new_ctx as long as the related thread is reachable
|
|
* from a garbage collection point of view.
|
|
*/
|
|
|
|
duk_push_string(new_ctx, "foo");
|
|
|
|
/* This duk_pop() makes the new thread unreachable (assuming there
|
|
* is no other reference to it), so new_ctx is no longer valid
|
|
* afterwards.
|
|
*/
|
|
|
|
duk_pop(ctx);
|
|
|
|
/* Using new_ctx here may cause a crash. */
|
|
|
|
=tags
|
|
stack
|
|
borrowed
|
|
|
|
=introduced
|
|
1.0.0
|
|
|