Index: compiled/bindings/generator.h |
=================================================================== |
--- a/compiled/bindings/generator.h |
+++ b/compiled/bindings/generator.h |
@@ -175,40 +175,58 @@ namespace bindings_internal |
}; |
struct DifferentiatorInfo |
{ |
size_t offset; |
std::vector<std::pair<int, std::string>> mapping; |
}; |
+ typedef std::vector<PropertyInfo> Properties; |
+ typedef std::vector<MethodInfo> Methods; |
+ |
struct ClassInfo |
{ |
TYPEID id; |
TYPEID baseClass; |
std::string name; |
- std::vector<PropertyInfo> properties; |
- std::vector<MethodInfo> methods; |
+ Properties properties; |
+ Methods methods; |
DifferentiatorInfo subclass_differentiator; |
ptrdiff_t ref_counted_offset; |
}; |
+ struct NamespaceInfo |
+ { |
+ std::string name; |
+ Properties properties; |
+ Methods methods; |
+ }; |
+ |
void register_class(const char* name, TYPEID classID, TYPEID baseClassID, |
ptrdiff_t ref_counted_offset); |
void register_property(TYPEID classID, const char* name, |
const FunctionInfo& getter, const FunctionInfo& setter, |
const char* jsValue = ""); |
void register_method(TYPEID classID, const char* name, |
const FunctionInfo& call); |
void register_differentiator(TYPEID classID, size_t offset, |
std::vector<std::pair<int, std::string>>& mapping); |
+ void register_namespace(const char* name); |
+ |
+ void register_namespace_property(const char* namespaceName, const char* name, |
+ const FunctionInfo& getter, const FunctionInfo& setter); |
+ |
+ void register_namespace_method(const char* namespaceName, const char* name, |
+ const FunctionInfo& call); |
+ |
std::string wrapCall(const FunctionInfo& call, bool isFunction = true); |
} |
template<typename ClassType, |
typename BaseClass = bindings_internal::NoBaseClass, |
typename std::enable_if<std::is_base_of<ref_counted, ClassType>::value>::type* = nullptr> |
class class_ |
{ |
@@ -283,9 +301,39 @@ public: |
mapping.emplace_back(item.first, item.second); |
bindings_internal::register_differentiator( |
bindings_internal::TypeInfo<ClassType>(), offset, mapping); |
return *this; |
} |
}; |
+class namespace_ |
+{ |
+private: |
+ const char* mName; |
+ |
+public: |
+ namespace_(const char* name) |
+ : mName(name) |
+ { |
+ bindings_internal::register_namespace(name); |
+ } |
+ |
+ template<typename FieldType> |
+ namespace_& property(const char* name, |
+ FieldType (*getter)(), |
+ void (*setter)(FieldType) = nullptr) |
+ { |
+ bindings_internal::register_namespace_property(mName, name, getter, |
+ setter); |
+ return *this; |
+ } |
+ |
+ template<typename ReturnType, typename... Args> |
+ namespace_& function(const char* name, ReturnType (*method)(Args...)) |
+ { |
+ bindings_internal::register_namespace_method(mName, name, method); |
+ return *this; |
+ } |
+}; |
+ |
void printBindings(); |