-5

I have a quit big c++ program and I want to have a function which I can edit in a text file to change the behavior of my c++ program without compiling it again.

To achieve this I thought I could embed a script in my c++ program.

My function should take two c++ objects and return a boolean in relation to the two objects and their members. The pseudo code would be similar to the following:

//In c++ program
CppObject cpp1, cpp2;
ScSriptObject o1 = transform(cpp1);
ScriptObject o2 = transform(cpp2);
boolean result = call function(o1, o2);

//Script function in text file
boolean function(Object o1, Object o2)
{
return do_something(o1, o2)
}

I would like to know if there is another maybe better solution. And with which scripting languages can this be done easily and how can it be done?

I have already taken a look at python and Python/C API, but I had some troubles to get the basic examples working and I'm wondering if there is a simpler option.

Thank you for your help :)

Jakob
  • 1
  • 1

1 Answers1

-1

If you're using linux, you could use system function to call for an external script which you could edit whenever you decide to, without compiling again. Eg.:

int res = system("/usr/local/bin/myscript.sh");
if (res == 0)
{
    // exited normally
}
else
{
    // abnormal exit
}

On windows you could use a similar approach, as system in platform independent. One more thing, mind the endianness of the result! For further reading about system, you could use this answer or this almost full explanatory link on cplusplus.com. Hope it helps, cheers.

veliki
  • 41
  • 1
  • 8