Sign in to follow this  

C++ Calling functions from text?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all, i've been wondering for a while if you could call a function from text for example; say you have a XML file that stores the information about an item in game and it would have a variable called "function" and you could set that too "foo" would it be possible to then be able to read that variable in game and call the function "foo"?

Share this post


Link to post
Share on other sites
Not in C++ without specifying/interpreting the mapping yourself. There's no mechanism to do it automatically, or reflection that would allow you to generate/find the function.

Share this post


Link to post
Share on other sites
It can be done, but C++ has no built in methods to do so. You need to manually parse the text data for the names "function" and "foo" and then manually decide how the function should be called (or use a third party tool or tools that will do some of this work for you). The relevant topics are called lexical analysis (or just lexing) and parsing.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this