__object.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * 文件名: __object.h
  3. * 目标: 定义aft对象的结构体
  4. */
  5. #ifndef AFUN__OBJECT_H
  6. #define AFUN__OBJECT_H
  7. // 这些typedef可能会被下面include的文件使用
  8. typedef struct af_ObjectData af_ObjectData;
  9. typedef struct af_ObjectAPINode af_ObjectAPINode;
  10. typedef struct af_ObjectAPI af_ObjectAPI;
  11. #include "macro.h"
  12. #include "tool.h"
  13. #include "object.h"
  14. #include "__gc.h"
  15. #define API_HASHTABLE_SIZE (8)
  16. typedef void pValueAPI();
  17. NEW_DLC_SYMBOL(pValueAPI, pAPIFUNC);
  18. struct af_ObjectAPINode {
  19. char *name; // api名字
  20. DLC_SYMBOL(pAPIFUNC) api; // api函数
  21. struct af_ObjectAPINode *next;
  22. };
  23. struct af_ObjectAPI {
  24. uint32_t count; // api个数记录
  25. struct af_ObjectAPINode *(node[API_HASHTABLE_SIZE]);
  26. };
  27. struct af_ObjectData {
  28. char *id; // 对象类型标识符(一个字符串)
  29. void *data;
  30. size_t size; // 标记data的大小
  31. struct af_ObjectAPI *api; // 继承的api必须位于Inherit链中
  32. bool allow_inherit; // 是否允许被继承
  33. bool inherit_api; // api被继承
  34. struct af_VarSpace *var_space;
  35. struct af_Inherit *iherit; // 只有顶级继承对象的iherit属性可为NULL
  36. struct af_Object *base; // 在gc机制中, 当对想要被释放前, 调用析构函数是对象以该base的身份出现
  37. GC_ObjectData gc;
  38. };
  39. struct af_Object {
  40. struct af_Object *belong; // 只有顶级属对象的belong属性可为NULL
  41. struct af_ObjectData *data;
  42. GC_Object gc;
  43. };
  44. struct af_Inherit {
  45. struct af_Object *obj;
  46. struct af_Inherit *next;
  47. };
  48. void freeObjectData(af_ObjectData *od); // gc使用
  49. int addAPIToObjectData(DlcHandle *dlc, char *func_name, char *api_name,
  50. af_ObjectData *od);
  51. af_ObjectAPINode *findObjectDataAPINode(char *api_name, af_ObjectData *od);
  52. #endif //AFUN__OBJECT_H