Aspects

An “aspect” is an interface (struct of function pointers) identified by a unique identifier. The Truth allows you to associate aspects with object types. This lets you extend The Truth with new functionality. For example, you could add an interface for debug printing an object:

#define tm_debug_print_aspect_i_hash                                           \
  TM_STATIC_HASH("tm_debug_print_aspect_i", 0x39821c78639e0773ULL)

typedef struct tm_debug_print_aspect_i {
  void (*debug_print)(tm_the_truth_o *tt, tm_tt_id_t object);
} tm_debug_print_aspect_i;

Note: to genereate the TM_STATIC_HASH you need to run hash.exe or tmbuild.exe --gen-hash for more info open the hash.exe guide

You could then use this code to debug print an object o with:

static void example_use_case(tm_the_truth_o *tt, tm_tt_id_t object) {
  tm_debug_print_aspect_i *dp =
      tm_tt_get_aspect(tt, tm_tt_type(object), tm_debug_print_aspect_i);
  if (dp)
    dp->debug_print(tt, object);
}

Note: that plugins can extend the system with completely new aspects.

The best example of how the Engine is using the aspect system is the tm_properties_aspect_i which helps us to defines custom UIs for Truth objects.

Contributors

Simon Renger Simon Renger