C++ turning "APP.QUIT()" (a string) into actual code
#1 Members - Reputation: 103
Posted 17 February 2012 - 05:19 PM
"app.quit()"
and in game make the game quit. I started now by writing
if(ClassDepth[0]=="app")
{
if(ClassDepth[1]=="quit"){app.quit();}
}
but it will take a long time to re write everything. is there any way to make this easier?
#2 Senior Moderators - Reputation: 2448
Posted 17 February 2012 - 05:28 PM
ScapeCode - Blog | SlimDX
#5 Members - Reputation: 1199
Posted 17 February 2012 - 08:06 PM
The voices in my head may not be real, but they have some good ideas!
#6 Members - Reputation: 1170
Posted 18 February 2012 - 12:45 AM
struct action : uncopyable
{
action() { }
virtual ~action() { }
virtual void invoke() = 0;
};
struct quit_action : action
{
quit_action(Application &app) : app(app) { }
virtual void invoke() { app.quit(); }
Application &app;
};
// ...
std::map<std::string, shared_ptr<action> > actions;
actions["quit"].reset(new quit_action(the_app));
// ...
bool do_action(const std::string &name)
{
std::map<std::string, shared_ptr<action> >::iterator f = actions.find(name);
if (f != actions.end())
{
(*f)->invoke();
return true;
}
return false;
}
If your actions need parameters, you might pass those via a stack, once parsed out of the command string, and each action's invoke() method would attempt to pop them as needed before use (with appropriate checking for underflow).
I'd also agree that Lua is a good idea in principle, but it might actually be more work to do it that way, especially to someone that's relatively new to C++. On the other hand, using a proper scripting language opens up your code to all kinds of other possibilities...
#7 Members - Reputation: 1216
Posted 18 February 2012 - 02:40 AM
[edit]
Google's protocol buffers (protobuf) apparently does RPC too.
#9 Members - Reputation: 1216
Posted 18 February 2012 - 03:02 PM
IceBreaker23, on 18 February 2012 - 11:29 AM, said:
#11 Members - Reputation: 2303
Posted 20 February 2012 - 09:18 AM
IceBreaker23, on 20 February 2012 - 08:56 AM, said:
On Android, Java is statically compiled, exactly the same way as C++.
On most modern x86 CPUs even native code is "interpreted", at very least the instructions that CPU executes are defined via microcode rather than being implemented directly.
Quote
Of course there is, it's just a bit of work. Structure data must either be manually defined or somehow generated by compiler or some other tool.
C++ doesn't offer reflection out-of-box due to optimization. A compiler is free to remove anything it deems redundant, including structures and functions. Full reflection would require preserving even unused parts. Templates in particular cause unacceptable overhead without such optimization.
#12 Members - Reputation: 110
Posted 21 February 2012 - 02:21 PM
Antheus, on 20 February 2012 - 09:18 AM, said:
IceBreaker23, on 20 February 2012 - 08:56 AM, said:
On Android, Java is statically compiled, exactly the same way as C++.
On most modern x86 CPUs even native code is "interpreted", at very least the instructions that CPU executes are defined via microcode rather than being implemented directly.
Quote
Of course there is, it's just a bit of work. Structure data must either be manually defined or somehow generated by compiler or some other tool.
C++ doesn't offer reflection out-of-box due to optimization. A compiler is free to remove anything it deems redundant, including structures and functions. Full reflection would require preserving even unused parts. Templates in particular cause unacceptable overhead without such optimization.
Really usefull knowledge
Thank you.
#13 Members - Reputation: 697
Posted 21 February 2012 - 02:30 PM
Antheus, on 20 February 2012 - 09:18 AM, said:
#14 Members - Reputation: 2303
Posted 21 February 2012 - 05:18 PM
Martins Mozeiko, on 21 February 2012 - 02:30 PM, said:
Antheus, on 20 February 2012 - 09:18 AM, said:


















