name: duk_get_global_string proto: | duk_bool_t duk_get_global_string(duk_context *ctx, const char *key); stack: | [ ... ] -> [ ... val! ] (if key exists) [ ... ] -> [ ... undefined! ] (if key doesn't exist) summary: |

Get property named key from the global object. Returns non-zero if the property exists and zero otherwise. This is a convenience function which does the equivalent of:

  duk_bool_t ret;

  duk_push_global_object(ctx);
  ret = duk_get_prop_string(ctx, -1, key);
  duk_remove(ctx, -2);
  /* 'ret' would be the return value from duk_get_global_string() */
  
example: | (void) duk_get_global_string(ctx, "encodeURIComponent"); duk_push_string(ctx, "foo bar"); duk_call(ctx, 1); /* [ ... encodeURIComponent "foo bar" ] -> [ "foo%20bar" ] */ printf("encoded: %s\n", duk_to_string(ctx, -1)); duk_pop(ctx); tags: - property seealso: - duk_get_global_lstring - duk_put_global_string - duk_put_global_lstring introduced: 1.0.0