diff options
Diffstat (limited to 'system/lib/embind/bind.cpp')
-rwxr-xr-x | system/lib/embind/bind.cpp | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/system/lib/embind/bind.cpp b/system/lib/embind/bind.cpp index c7c1f4b4..673fdf1a 100755 --- a/system/lib/embind/bind.cpp +++ b/system/lib/embind/bind.cpp @@ -1,7 +1,10 @@ #include <emscripten/bind.h>
#include <..\lib\libcxxabi\src\private_typeinfo.h>
+#include <..\lib\libcxxabi\include\cxxabi.h>
#include <list>
#include <vector>
+#include <typeinfo>
+#include <algorithm>
#include <emscripten/emscripten.h>
using namespace emscripten;
@@ -101,13 +104,6 @@ namespace emscripten { return pathsAsTypeInfo;
}
- // We bind __getDerivationPaths in order to take advantage of the std::vector to Javascript array
- // conversion for the return value. This has the unfortunate side-effect of exposing it to third party
- // developers, but perhaps the double underscore will scare them away from calling it.
- EMSCRIPTEN_BINDINGS(([]() {
- function("__getDerivationPaths", &__getDerivationPaths);
- }));
-
// __getDynamicPointerType returns (for polymorphic types only!) the type of the instance actually
// pointed to.
int EMSCRIPTEN_KEEPALIVE __getDynamicPointerType(int p) {
@@ -117,7 +113,7 @@ namespace emscripten { // Calls to __dynamic_cast are generated by the compiler to implement dynamic_cast<>() -- its prototype is
// not available through any header file. It is called directly here because it allows run-time
- // specification of the target pointer type (which must be specified at compile time when using
+ // specification of the target pointer type (which can only be specified at compile time when using
// dynamic_cast<>().
void* __dynamic_cast(void*, const std::type_info*, const std::type_info*, int);
@@ -128,6 +124,30 @@ namespace emscripten { // in the emscripten runtime. The compiler passes a dummy value of -1, and so do we.
return (int)__dynamic_cast((void *)p, (const std::type_info*)from, (const std::type_info *)to, -1);
}
+
+ const char* EMSCRIPTEN_KEEPALIVE __typeName(int p) {
+ const std::type_info* ti = (const std::type_info*)p;
+ size_t nameLen = std::min(strlen(ti->name()), (unsigned int)1024);
+ char* name = (char *)malloc(nameLen+1);
+ int stat;
+
+ __cxxabiv1::__cxa_demangle(ti->name(), name, &nameLen, &stat);
+
+ if (stat != 0) {
+ strncpy(name, ti->name(), nameLen);
+ name[nameLen] = '\0';
+ }
+ return name;
+ }
+
+ EMSCRIPTEN_BINDINGS(([]() {
+ // We bind __getDerivationPaths in order to take advantage of the std::vector to Javascript array
+ // conversion for the return value. This has the unfortunate side-effect of exposing it to third party
+ // developers, but perhaps the double underscore will scare them away from calling it.
+ function("__getDerivationPaths", &__getDerivationPaths);
+ }));
+
+
}
}
}
|