Property Binding Redemption Arc

This week I try to atone for my sins.

Proper Properties

I’ve got to get better at this socializing or social media or self-presentation and promotion, right? Last weekend I transcribed my thoughts into a YouTube slideshow …

LINK >

… and I missed an issue that meant I needed to replace all of it. Quite embarrassing.

The Issue

I’m binding and “instrumenting” C++/17 classes via Template Meta Programming. I want to bind/instrument C++ code with one set of defs, to three systems, with “negligible” overhead. To do this - I’m working with method pointers. To test this, I tried to write classes in #define macro() blocks that used if constexpr to branch and return void or a pal:etry<void> error monad.

That didn’t work;

  • the void methods can’t have a …
    #define RES(KEY, T)                           \
      struct KEY ## _class                        \
      {                                           \
        int _ ## KEY;                             \
        T KEY(int KEY)                            \
        {                                         \
          _ ## KEY = KEY;                         \
          if constexpr(std::is_same_v<void, T>)   \
          {                                       \
            return;                               \
          } else {                                \
            return pal:etry<void>::pass();        \
          }                                       \
        }                                         \
      };                                          \
    ...
    RES(foo1, void);
    RES(foo2, pal::etry<void>);
    

    … since C++ is too dumb / smurt enuff to notice those return types don’t match.

    Not a concern for IRL usage; just for generating test cases with macros and TMP.

  • One also can’t do …
    template<class R>
    struct SUPER<R>
    {
      R bar(float bar)
      {
        ...
        if constexpr(std::is_same_v<void, R>)
        {
          return;
        } else {
          return pal:etry<void>::pass();
        }
      }
    };
    struct CHILD : SUPER<void>
    {
    };
    

    … since CHILD::bar doesn’t exist - only SUPER<void>::bar exists.

Fine.

The Fix

#define PROPERTY_TEST_CLASS(KEY, R, P)        \
  struct property_example_ ## KEY             \
  {                                           \
    int _value;                               \
    R value(int value)                        \
    {                                         \
      _value = value;                         \
      P;                                      \
    }                                         \
  };                                          \
  p_test_case(property_test_ ## KEY)          \
  {                                           \
     ...                                      \
  }                                           \

PROPERTY_TEST_CLASS(01, void,             {});
PROPERTY_TEST_CLASS(02, pal::etry<void>,  { return pal:etry<void>::pass(); });

Reflection and the Future

This is for a game engine. I (like many others) am attempting to produce a game engine - almost from scratch. Part of this involves scripting serialisation and inspection or SSI of data, or, code objects.

That’s not something I see a lot of good/usable COTS/FOSS tools for. So … a valid area of special interest?

Anyway

I put the above hijinks into a file, then, use a Python script to generate permutations of the classes and tests. It’s up to 64 variations - I also test some cases by hand.

Current Headache

The getter and setter will need to take “context” data. I’ve been reluctant to “lock in” to one datatype … but as of this writing …

It should just be an optional entt::registry& parameter. All signatures should/can/do take an optional entt::registry& parameter.

  • Duktape callbacks can live with this; they can retrieve it
  • Duktape might be retired/replaced with Lua
  • entt has a conventional entt::registry::ctx<T>(): T&

… again; F I I N N N E E E E

Concludes

So that’s my weekend planned;

  • Resident Evil / Endgame (IDK)
  • SprueCon
  • set-up hgkeeper
    • … and backups …
    • … Drone CI …
    • … and mirror to … idk … sr.ht? HgLab?
    • … and some RO Kanban Board
  • sweep-through my project tree
    • pal::context is RO and init from `pal::context
comments powered by Disqus
Peter LaValle avatar
Peter LaValle
Any links probably include affiliate ids for that sweet sweet kickback - and some programs require that I tell you. The contents of this blog are likely unrelated - as they include games, paints, and build tools.