The table below summarizes API calls to read a value of a certain type (e.g. a string).
Value stack entry type | duk_get_xxx() | duk_get_xxx_default() | duk_require_xxx() | duk_opt_xxx() | duk_to_xxx() |
---|---|---|---|---|---|
none (index out of bounds) | default (automatic) | default (explicit) | TypeError | default (explicit) | TypeError |
undefined | default (automatic) | default (explicit) | TypeError | default (explicit) | coercion |
null | default (automatic) | default (explicit) | TypeError | TypeError | coercion |
Matching type | as is | as is | as is | as is | as is |
Non-matching type | default (automatic) | default (explicit) | TypeError | TypeError | coercion |
Concrete example for string values:
Value stack entry type | duk_get_string() | duk_get_string_default() | duk_require_string() | duk_opt_string() | duk_to_string() |
---|---|---|---|---|---|
none (index out of bounds) | NULL | default (explicit) | TypeError | default (explicit) | TypeError |
undefined | NULL | default (explicit) | TypeError | default (explicit) | "undefined" |
null | NULL | default (explicit) | TypeError | TypeError | "null" |
boolean | NULL | default (explicit) | TypeError | TypeError | "true" |
number | NULL | default (explicit) | TypeError | TypeError | "123.4" |
string | "hello" | "hello" | "hello" | "hello" | |
object | NULL | default (explicit) | TypeError | TypeError | "[object Object]" |
buffer | NULL | default (explicit) | TypeError | TypeError | "[object ArrayBuffer]" |
pointer | NULL | default (explicit) | TypeError | TypeError | "0xdeadbeef" |
lightfunc | NULL | default (explicit) | TypeError | TypeError | "function light_08062727_0a11() { [lightfunc code] }" |
Notes:
- Integer getters do a double-to-integer coercion for the API return value. This coercion does not change the number on the value stack which remains a double.