=proto
void duk_get_var(duk_context *ctx);
=stack
[ ... varname! ] -> [ ... val! ]
=summary
Look up identifier varname
. Possible outcomes:
- If identifier is found, replaces
varname
with its value on the
value stack and returns.
- If identifier is not found, throws a
ReferenceError
(this applies
to both strict and non-strict code).
- If the input stack is empty (or some other internal error occurs),
throws an error.
The identifier lookup is equivalent to the Ecmascript expression:
varname
For semantics, see
Identifier Resolution,
GetIdentifierReference (lex, name, strict),
Identifier Reference,
GetValue (V).
Ecmascript semantics require that a ReferenceError
be thrown if the identifier
cannot be resolved (this is the case even in non-strict mode).
Because Duktape/C functions cannot currently be nested functions, their
outer lexical environment is always the global environment.
=example
duk_push_string(ctx, "Math");
duk_get_var(ctx); /* [ ... "Math" ] -> [ ... Math ] */
duk_get_prop_string(ctx, -1, "PI"); /* -> [ ... Math PI ] */
printf("Math.PI=%lf\n", duk_get_number(ctx, -1));
duk_pop_2(ctx);
=tags
variable
omit
=fixme
Although Ecmascript semantics always require a ReferenceError for
unresolvable identifiers, it might fit the API better to return zero
if identifier is not found and non-zero if found. This would match
the property access API. Incomplete.