Macro Laziness

This topic is 5502 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I'm trying to create some lazy macros. My scripting engine must be set up with pointers to variables and have an identification text version of that same variable. Like this..
Script->AddVariable(&MyInt, "MyInt");

As you can see, the names always match. Now imagine about 500 of these. It's ugly, and a maintenance nightmare. Actually, there are only a few of the AddVariable type lines, but many, many values. Are there any ways I can cheat here? At least on the value versions? How can I give the scripting engine the value of an enum and it's text name all at once?
#define ADD_VALUE(_eval_) AddValue(_eval_,"_eval_");
It would be even cooler to go through a loop for the whole slew of enum values of each type, but I'm almost sure the IDE wouldn't allow such hacking.
for(int i=0; i<ENUM_MAX; i++)
AddValue( GetEnumValue(i), GetEnumLabel(i) );
The scripting engine is of my own creation, so feel free to offer any advice on how to avoid this situation to begin with. Thanks for any advice.

Share on other sites
Use Stringification:

#define ADD_VALUE(EXP) AddValue(EXP, #EXP);

Share on other sites
#define ADD_VALUE(_eval_) AddValue(_eval_,#_eval_);

EDIT: you beat me!

Share on other sites
Quote:
 Original post by mandrav#define ADD_VALUE(EXP) AddValue(EXP, #EXP);

But of course, this does not work dynamically, although maybe it doesn't need to.

Share on other sites
Ahhh wow, really nice. Thanks. One little operator.

Quote:
 Original post by swiftcoderBut of course, this does not work dynamically, although maybe it doesn't need to.

To sound like an idiot: What do you mean dynamically?

• Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 14
• 30
• 9
• 16
• 22