diff options
-rw-r--r-- | system/include/emscripten/val.h | 22 | ||||
-rw-r--r-- | tests/embind/embind_test.cpp | 4 |
2 files changed, 9 insertions, 17 deletions
diff --git a/system/include/emscripten/val.h b/system/include/emscripten/val.h index 42d8d375..09cad80e 100644 --- a/system/include/emscripten/val.h +++ b/system/include/emscripten/val.h @@ -56,25 +56,17 @@ namespace emscripten { } } - class symbol { - public: - symbol() = delete; - - // I so wish I could require the argument to be a string literal - symbol(const char* address) - : address(address) - { + template<const char* address> + struct symbol_registrar { + symbol_registrar() { internal::_emval_register_symbol(address); } - - operator const char*() const { - return address; - } - - private: - const char* address; }; +#define EMSCRIPTEN_SYMBOL(name) \ + static const char name##_symbol[] = #name; \ + static const symbol_registrar<name##_symbol> name##_registrar + class val { public: // missing operators: diff --git a/tests/embind/embind_test.cpp b/tests/embind/embind_test.cpp index 9bab2872..04771dbe 100644 --- a/tests/embind/embind_test.cpp +++ b/tests/embind/embind_test.cpp @@ -1087,7 +1087,7 @@ public: }
};
-symbol optionalMethodSymbol = "optionalMethod";
+EMSCRIPTEN_SYMBOL(optionalMethod);
class AbstractClassWrapper : public wrapper<AbstractClass> {
public:
@@ -1097,7 +1097,7 @@ public: return call<std::string>("abstractMethod");
}
std::string optionalMethod(std::string s) const {
- return optional_call<std::string>(optionalMethodSymbol, [&] {
+ return optional_call<std::string>(optionalMethod_symbol, [&] {
return AbstractClass::optionalMethod(s);
}, s);
}
|