Compile-time testing for the (non-)existence of objects?

Is there any way to do something like

#ifndef foozle
foozle() { return('foo'); }

…in TADS3?

I’ve been putting together a module for various kinds of “complicated” furniture I’m using in my WIP. Some of them, like shop counters, allow actors to stand/go behind them.

In my WIP, I’m (probably) going to use the ConSpace module, which implements a StandBehind action.

What I’d like to be able to do is write the furniture module such that it doesn’t depend ConSpace, using an existing StandBehindAction if it exists or defining its own if it doesn’t.

But beyond this specific case, it would be kinda nice to have some way of dependency checking at compile time if the module isn’t polite enough to include a #define indicating its existence.

Maybe defined() will do what you want? (Works both with preprocessor and runtime, although in different capacities.)

1 Like

I don’t think I can get where I need to go with defined(), because in an #if (or other preprocessor) context it works the same way as #ifdef. Unless I’m missing something. That is, in a preprocessor block it just checks for preprocessor symbols.

In theory I could put a defined() check in a method somewhere, like a PreinitObject…but then I can’t define things like Actions that are used elsewhere (like in dobjFor() methods) because the compiler will error out if the actions aren’t defined at compile-time.