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.
 
 
 
 
 
 

38 lines
1.1 KiB

name: duk_set_global_object
proto: |
void duk_set_global_object(duk_context *ctx);
stack: |
[ ... new_global! ] -> [ ... ]
summary: |
<p>Replace the current context's global object with the object on top of the
value stack. If the value is not an object, an error is thrown.</p>
<p>Note that this operation <b>does not</b> affect the global object of other
contexts, even those that have up to this point shared the same global
environment. To inherit the change to other contexts, replace the global
object first before calling <code>duk_push_thread()</code>.</p>
<p>See the test case
<a href="https://github.com/svaarala/duktape/blob/master/tests/api/test-set-global-object.c">test-set-global-object.c</a>
for discussion of detailed behavior after the change.</p>
example: |
/* Build a global object with a subset of bindings. */
duk_eval_string(ctx,
"({\n"
" print: this.print,\n"
" JSON: this.JSON\n"
"})\n");
/* Replace global object. */
duk_set_global_object(ctx);
tags:
- stack
- thread
- sandbox
introduced: 1.0.0