| 49 | |
| 50 | template<class Base, class Derived> |
| 51 | void dukglue_set_base_class(duk_context* ctx) |
| 52 | { |
| 53 | static_assert(!std::is_pointer<Base>::value && !std::is_pointer<Derived>::value |
| 54 | && !std::is_const<Base>::value && !std::is_const<Derived>::value, "Use bare class names."); |
| 55 | static_assert(std::is_base_of<Base, Derived>::value, "Invalid class hierarchy!"); |
| 56 | |
| 57 | using namespace dukglue::detail; |
| 58 | |
| 59 | // Derived.type_info->set_base(Base.type_info) |
| 60 | ProtoManager::push_prototype<Derived>(ctx); |
| 61 | duk_get_prop_string(ctx, -1, "\xFF" "type_info"); |
| 62 | TypeInfo* derived_type_info = static_cast<TypeInfo*>(duk_require_pointer(ctx, -1)); |
| 63 | duk_pop_2(ctx); |
| 64 | |
| 65 | ProtoManager::push_prototype<Base>(ctx); |
| 66 | duk_get_prop_string(ctx, -1, "\xFF" "type_info"); |
| 67 | TypeInfo* base_type_info = static_cast<TypeInfo*>(duk_require_pointer(ctx, -1)); |
| 68 | duk_pop_2(ctx); |
| 69 | |
| 70 | derived_type_info->set_base(base_type_info); |
| 71 | |
| 72 | // also set up the prototype chain |
| 73 | ProtoManager::push_prototype<Derived>(ctx); |
| 74 | ProtoManager::push_prototype<Base>(ctx); |
| 75 | duk_set_prototype(ctx, -2); |
| 76 | duk_pop(ctx); |
| 77 | } |
| 78 | |
| 79 | // methods |
| 80 | template<typename T, T Value, class Cls, typename RetType, typename... Ts> |