0

I have a function as shown below:

bool setJavaScript(int time , const str::string text)
{

d->setJavaTimeOut(time, &shouldTerminate);

}

...and the function shouldTerminate is like this :

bool shouldTerminate(JSContextRef ctx, void* context)
{

}

Now, I want the variable text in setJavaScript to be accessed in shouldTerminate, how do I do that?

Both functions are in same file.

The variable text has been sent by another function from different file.

Holt
  • 36,600
  • 7
  • 92
  • 139
SirKappe
  • 55
  • 1
  • 7
  • Use a global variable visible from both functions. Utilize `extern` if needed. – Ron Sep 28 '17 at 11:34
  • 1
    You may pass "text" as a parameter to setJavaTimeOut also, which you may pass to shouldTerminate. You have to change the signature of setJavaTimeOut though. – Nipun Talukdar Sep 28 '17 at 11:37
  • 2
    Could it make sense to make both functions be methods of a class? – Serge Ballesta Sep 28 '17 at 11:42
  • How do you set context to be passed to the shouldTerminate? – Artemy Vysotsky Sep 28 '17 at 11:58
  • Is the text a compile time constant? If not, then are you able to modify d and store text in the context? If you have to bypass the backend entirely, I tried passing a lambda which captures text, but you can't convert that to a function pointer (because where is it stored? what is the lifetime of the capture?) ... but you could possibly achieve it with std::function as recommended in https://stackoverflow.com/questions/28746744/passing-lambda-as-function-pointer – Kenny Ostrom Sep 28 '17 at 13:35

0 Answers0