#include <Ultralight/js/Value.h>
An argument passed to a bound function.
An Arg is only valid during the callback that received it (it adds no reference, so reading it is cheap). Call ToValue() to keep the argument after the callback returns.
An Arg has To(), Maybe(), and Or(). Other conversions need a Value first (eg, arg.ToValue().ToNumber()).
- See also
- CallInfo::arg()
|
| | Arg (ULJSValue borrowed) |
| | Wrap a borrowed handle.
|
| bool | IsEmpty () const |
| | Whether or not the argument is absent (the call passed fewer arguments than the index given to CallInfo::arg()).
|
| Type | type () const |
| | Get the argument's type (Type::Invalid if the argument is absent).
|
| template<typename T> |
| Result< T > | To () const |
| | Convert to a C++ type (see Value::To()).
|
| template<typename T> |
| std::optional< T > | Maybe () const |
| | Convert to a C++ type like To() but without the failure reason.
|
| template<typename T> |
| T | Or (T fallback) const |
| | Convert to a C++ type like To() but with a fallback.
|
| std::string | Or (const char *fallback) const |
| | Convert to a std::string like To() but with a string-literal fallback.
|
| Value | ToValue () const |
| | Get a Value that keeps the argument after the callback returns.
|
| ULJSValue | raw () const |
| | Get the C API handle.
|
◆ Arg()
| Arg |
( |
ULJSValue | borrowed | ) |
|
|
inlineexplicit |
Wrap a borrowed handle.
- Parameters
-
| borrowed | The handle (valid only during the callback). |
- Note
- You normally get an Arg from CallInfo::arg() instead of creating one.
◆ IsEmpty()
Whether or not the argument is absent (the call passed fewer arguments than the index given to CallInfo::arg()).
- Note
- An absent argument converts only to an optional type (as an empty optional). Any other To() fails with a TypeError, and ToValue() returns an empty Value.
◆ Maybe()
template<typename T>
| std::optional< T > Maybe |
( |
| ) |
const |
|
nodiscard |
Convert to a C++ type like To() but without the failure reason.
- Returns
- Returns the converted value or nullopt on any failure.
◆ Or() [1/2]
| std::string Or |
( |
const char * | fallback | ) |
const |
|
nodiscard |
Convert to a std::string like To() but with a string-literal fallback.
- Parameters
-
| fallback | The text to return if the conversion fails. |
- Returns
- Returns the converted string or fallback on any failure.
◆ Or() [2/2]
Convert to a C++ type like To() but with a fallback.
- Parameters
-
| fallback | The value to return if the conversion fails. |
- Returns
- Returns the converted value or fallback on any failure.
◆ raw()
Get the C API handle.
- Returns
- Returns the handle (valid only during the callback).
◆ To()
◆ ToValue()
Get a Value that keeps the argument after the callback returns.
- Returns
- Returns the new Value.
◆ type()
Get the argument's type (Type::Invalid if the argument is absent).
The documentation for this class was generated from the following file: