diff --git a/include/tr/class.h b/include/tr/class.h index 63f5fd8..f656da9 100644 --- a/include/tr/class.h +++ b/include/tr/class.h @@ -84,7 +84,7 @@ * even compile. */ #define TR_EXTENDS(parent) const char _[sizeof(struct c_##parent)] -#define TR_CV_EXTENDS(parent) const char _[sizeof(struct c_##parent##_vars)] +#define TR_CV_EXTENDS(parent) struct c_##parent##_vars _ /** * Some macros might translate a give NULL to _NULL, @@ -107,13 +107,13 @@ * created. */ #define TR_CREATE_CLASS(name,_parent,cvInit,...) \ - struct c_##name##_vars c_vars; \ + struct c_##name##_vars _##name##_vars; \ void (* TR_initClassVars##name)(TR_class_ptr) = cvInit; \ static TR_class_ptr _classInit##name##_(void) { \ + c_##name.init = NULL; \ c_##name.parent = _##_parent; \ if (TR_initClassVars##name) \ TR_initClassVars##name(_##name); \ - c_##name.init = NULL; \ return &c_##name; \ }; \ struct TR_class c_##name = { \ @@ -121,11 +121,11 @@ NULL, \ sizeof(struct c_##name), \ _classInit##name##_, \ - &c_vars, \ + &_##name##_vars, \ TR_INIT_IFACE_IMPL(__VA_ARGS__) \ }; \ struct TR_class * const _##name = &c_##name; \ - struct c_##name##_vars c_vars + struct c_##name##_vars _##name##_vars /** * Create a static instance of a class. @@ -176,7 +176,10 @@ * \see TR_CREATE_CLASS */ #define TR_GET_CLASS(object) \ - (TR_INIT_CLASS(*(TR_class_ptr *)((void*)(object) - sizeof(void*)))) + (TR_INIT_CLASS(*(TR_class_ptr *)((void*)(object) - sizeof(void*)))) + +#define TR_CLASS_BY_NAME(class_name) (TR_INIT_CLASS(& c_##class_name)) +#define TR_CLASS_BY_NAME_STATIC(class_name) (& c_##class_name) /** * Returns this class's implementations of the interface