Smash
Smash

Reputation: 3802

C++ Command Line: Output program variable value

I am writing a drop-down console for my app. Suppose I want to output the value of variable myvar by using the following command:

]/get myvar

Is there a better way than to create a map so that the output is

return mymap[argv[0]]; ?

In other words, can I associate the input char array "myvar" to the variable named myvar without doing it manually for all the variables in the program.

Upvotes: 0

Views: 660

Answers (1)

Andrejs Cainikovs
Andrejs Cainikovs

Reputation: 28464

Short answer:

No.

Long answer:

Pfff, no way! After your piece of code is build as a binary, there is no such thing as a variable name. Just some pointers, values on the stack, and so on...

If you want to implement something like this, I would recommend you to go for a scripting library (Lua, for example), and manually map some variables so you can read/change those variables via scripts. In this case the console input is basically what you are feeding to the script engine.

This might be a good reference.

UPDATE:

In fact, just found the project called Lua Console.
Seems like it's not maintained anymore, but it doesn't mean it will not work.

Upvotes: 1

Related Questions