aboutsummaryrefslogtreecommitdiff
path: root/system
diff options
context:
space:
mode:
authorChad Austin <chad@imvu.com>2013-04-03 17:28:11 -0700
committerJukka Jylänki <jujjyl@gmail.com>2013-04-12 14:27:18 +0300
commitd4bf6fbe297ea7e5720b49bfa6fc58b696540144 (patch)
treeae9490c3bb37aef5afa0a4f9c25ee5b05edd8a6c /system
parent616b5c3579556c5e1be6ba1063c132680d9e2d43 (diff)
Add support for global constants.
Diffstat (limited to 'system')
-rwxr-xr-xsystem/include/emscripten/bind.h31
-rwxr-xr-xsystem/include/emscripten/wire.h2
2 files changed, 32 insertions, 1 deletions
diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h
index 4ecd35e9..e767afaa 100755
--- a/system/include/emscripten/bind.h
+++ b/system/include/emscripten/bind.h
@@ -159,6 +159,11 @@ namespace emscripten {
const char* name,
GenericFunction constructor,
GenericFunction destructor);
+
+ void _embind_register_constant(
+ const char* name,
+ TYPEID constantType,
+ uintptr_t value);
}
}
}
@@ -1023,6 +1028,32 @@ namespace emscripten {
}
};
+ ////////////////////////////////////////////////////////////////////////////////
+ // CONSTANTS
+ ////////////////////////////////////////////////////////////////////////////////
+
+ namespace internal {
+ template<typename T>
+ uintptr_t asGenericValue(T t) {
+ return static_cast<uintptr_t>(t);
+ }
+
+ template<typename T>
+ uintptr_t asGenericValue(T* p) {
+ return reinterpret_cast<uintptr_t>(p);
+ }
+ }
+
+ template<typename ConstantType>
+ void constant(const char* name, const ConstantType& v) {
+ using namespace internal;
+ typedef BindingType<const ConstantType&> BT;
+ _embind_register_constant(
+ name,
+ TypeID<const ConstantType&>::get(),
+ asGenericValue(BindingType<const ConstantType&>::toWireType(v)));
+ }
+
namespace internal {
template<typename T>
class optional {
diff --git a/system/include/emscripten/wire.h b/system/include/emscripten/wire.h
index 0c0f5eb8..9c8cd096 100755
--- a/system/include/emscripten/wire.h
+++ b/system/include/emscripten/wire.h
@@ -122,7 +122,7 @@ namespace emscripten {
template<> \
struct BindingType<type> { \
typedef type WireType; \
- constexpr static WireType toWireType(const type& v) { \
+ constexpr static WireType toWireType(const type& v) { \
return v; \
} \
constexpr static type fromWireType(WireType v) { \