aboutsummaryrefslogtreecommitdiff
path: root/system
diff options
context:
space:
mode:
Diffstat (limited to 'system')
-rwxr-xr-xsystem/include/emscripten/bind.h15
-rw-r--r--system/include/emscripten/val.h7
2 files changed, 21 insertions, 1 deletions
diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h
index d70aec91..07955d75 100755
--- a/system/include/emscripten/bind.h
+++ b/system/include/emscripten/bind.h
@@ -713,7 +713,7 @@ namespace emscripten {
template<typename T>
class wrapper : public T {
public:
- wrapper(const val& wrapped)
+ explicit wrapper(const val& wrapped)
: wrapped(wrapped)
{}
@@ -722,7 +722,20 @@ namespace emscripten {
return Caller<ReturnType, Args...>::call(wrapped, name, args...);
}
+ template<typename ReturnType, typename... Args, typename Default>
+ ReturnType optional_call(const char* name, Default def, Args... args) const {
+ if (has_function(name)) {
+ return Caller<ReturnType>::call(wrapped, name);
+ } else {
+ return def();
+ }
+ }
+
private:
+ bool has_function(const char* name) const {
+ return wrapped.has_function(name);
+ }
+
// this class only exists because you can't partially specialize function templates
template<typename ReturnType, typename... Args>
struct Caller {
diff --git a/system/include/emscripten/val.h b/system/include/emscripten/val.h
index 91f775a7..c27a0fdb 100644
--- a/system/include/emscripten/val.h
+++ b/system/include/emscripten/val.h
@@ -48,6 +48,9 @@ namespace emscripten {
unsigned argCount,
internal::TYPEID argTypes[]
/*, ...*/);
+ bool _emval_has_function(
+ EM_VAL value,
+ const char* methodName);
}
}
@@ -222,6 +225,10 @@ namespace emscripten {
toWireType(args)...);
}
+ bool has_function(const char* name) const {
+ return _emval_has_function(handle, name);
+ }
+
template<typename T>
T as() const {
using namespace internal;