Does someone know how I could look up local variables in a nested function call from C++?
Consider the following example:
// e.g. a global variable in the browser
var global = "global_value";
function foo(){
var global = "local_value";
myCppFunction("global", global);
}
foo();
My question now is how in the implementation of myCppFunction I could access the function local variable “global” (NOT value, this would be given by the 2nd parameter) from ‘foo’?
Handle<Value> MyCppFunction(const Arguments& args){
Local<String> varName = args[0]->ToString();
Local<String> varValue = args[1]->ToString(); // this holds "local_value"
// how to access the variable "global" in the scope of 'foo' ?
}
I managed to find it out by myself. See the example below for how to find the value on the stack (and also replace it – here by the example of a string variable).
Two remarks beforehand:
sfl.FindJavaScriptFrame(0)yields the desired stack frame – but, as it works independently of the calling depth, I suspect the stack frame indexed by 0 to always be the immediate caller’s frame (in my case I know that I want exactly that).And the code: