aboutsummaryrefslogtreecommitdiff
path: root/system/lib/embind/bind.cpp
blob: a5c878f5fd9679ad6e13869f1c900f1e1fc42281 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <emscripten/bind.h>
#include <../lib/libcxxabi/include/cxxabi.h>
#include <list>
#include <vector>
#include <typeinfo>
#include <algorithm>
#include <emscripten/emscripten.h>

using namespace emscripten;

extern "C" {
    const char* EMSCRIPTEN_KEEPALIVE __getTypeName(const std::type_info* ti) {
        int stat;
        char* demangled = abi::__cxa_demangle(ti->name(), NULL, NULL, &stat);
        if (stat == 0 && demangled) {
            return demangled;
        }

        switch (stat) {
            case -1:
                return strdup("<allocation failure>");
            case -2:
                return strdup("<invalid C++ symbol>");
            case -3:
                return strdup("<invalid argument>");
            default:
                return strdup("<unknown error>");
        }
    }
}

namespace emscripten {
    namespace internal {
        JSInterface* create_js_interface(EM_VAL e) {
            return new JSInterface(e);
        }
    }
}

EMSCRIPTEN_BINDINGS(native_and_builtin_types) {
    using namespace emscripten::internal;

    _embind_register_void(TypeID<void>::get(), "void");
    
    _embind_register_bool(TypeID<bool>::get(), "bool", true, false);

    _embind_register_integer(TypeID<char>::get(), "char");
    _embind_register_integer(TypeID<signed char>::get(), "signed char");
    _embind_register_integer(TypeID<unsigned char>::get(), "unsigned char");
    _embind_register_integer(TypeID<signed short>::get(), "short");
    _embind_register_integer(TypeID<unsigned short>::get(), "unsigned short");
    _embind_register_integer(TypeID<signed int>::get(), "int");
    _embind_register_integer(TypeID<unsigned int>::get(), "unsigned int");
    _embind_register_integer(TypeID<signed long>::get(), "long");
    _embind_register_integer(TypeID<unsigned long>::get(), "unsigned long");
    
    _embind_register_float(TypeID<float>::get(), "float");
    _embind_register_float(TypeID<double>::get(), "double");
    
    _embind_register_cstring(TypeID<std::string>::get(), "std::string");
    _embind_register_emval(TypeID<val>::get(), "emscripten::val");
}