The Embind C++ class emscripten::val
(defined in val.h) is used to transliterate JavaScript code to C++.
Guide material for this class can be found in Using val to transliterate JavaScript to C++.
emscripten::
val
¶This class is a C++ data type that can be used to represent (and provide convenient access to) any JavaScript object. You can use it to call a JavaScript object, read and write its properties, or coerce it to a C++ value like a bool
, int
, or std::string
.
For example, the code below shows some simple JavaScript for making an XHR request on a URL:
var xhr = new XMLHttpRequest;
xhr.open("GET", "http://url");
This same code can be written in C++, using global()
to get the symbol for the global XMLHttpRequest
object and then using it to open a URL.
val xhr = val::global("XMLHttpRequest").new_();
xhr.call("open", std::string("GET"), std::string("http://url"));
See Using val to transliterate JavaScript to C++ for other examples.
undefined
()¶Creates a val
that represents undefined
.
Returns: | The val that represents undefined . |
---|
null
()¶Creates a val
that represents null
. val::undefined()
is the same, but for undefined.
Returns: | A val that represents null . |
---|
take_ownership
(internal::EM_VAL e)¶HamishW-Replace with description.
Returns: | HamishW-Replace with description. |
---|
global
(const char *name)¶Looks up a global symbol.
Parameters: | const char* name – HamishW-Replace with description. |
---|---|
Returns: | HamishW-Replace with description. |
module_property
(const char *name)¶Looks up a symbol on the emscripten Module object.
Parameters: | const char* name – HamishW-Replace with description. |
---|---|
Returns: | HamishW-Replace with description. |
val
(T &&value)¶Constructor.
A val
can be constructed by explicit construction from any C++ type. For example, val(true)
or val(std::string("foo"))
.
Parameters: | T&& value – Any C++ type. |
---|
HamishW Don’t know how following “floating statement works”. Leaving here for discussion
val() = delete;
val
(const char *v)¶HamishW-Replace with description.
Parameters: | const char* v – HamishW-Replace with description. |
---|
val
(val &&v)¶HamishW-Replace with description.
Parameters: | val&& v – HamishW-Replace with description. |
---|
val
(const val &v)¶HamishW-Replace with description.
Parameters: | const val& v – HamishW-Replace with description. |
---|
~val
()¶Destructor. HamishW-Replace with further description or delete comment.
operator=
(val &&v)¶HamishW-Replace with description.
Parameters: | val&& v – HamishW-Replace with description. |
---|---|
Returns: | HamishW-Replace with description. |
operator=
(const val &v)¶HamishW-Replace with description.
Parameters: | val&& v – HamishW-Replace with description. |
---|---|
Returns: | HamishW-Replace with description. |
hasOwnProperty
(const char *key) const¶Test whether … HamishW-Replace with description.
Parameters: | const char* key – HamishW-Replace with description. |
---|---|
Returns: | HamishW-Replace with description. |
new_
()¶prototype:
template<typename... Args>
val new_(Args&&... args) const
HamishW-Replace with description.
Parameters: | Args&&... args – HamishW-Replace with description. Note that this is a templated value. |
---|---|
Returns: | HamishW-Replace with description. |
operator[]
(const T &key) const¶HamishW-Replace with description.
Parameters: | const T& key – HamishW-Replace with description. Note that this is a templated value. |
---|---|
Returns: | HamishW-Replace with description. |
set
(const K &key, const val &v)¶Set the specified (key
) property of a JavaScript object (accessed through a val
) with the value v
. HamishW-Replace with description.
Parameters: |
|
---|
operator()
(Args&&... args)¶HamishW-Replace with description.
Parameters: | Args&&... args – HamishW-Replace with description. Note that this is a templated value. |
---|
call
(const char *name, Args&&... args) const¶HamishW-Replace with description.
Parameters: |
|
---|
as
() const¶HamishW-Replace with description.
Returns: | HamishW-Replace with description. Note that this is a templated value. |
---|