0

I'm trying to modify a variable passed in an argument in a native function like this:

var MyVar = 'foo';
myNativeFunc(MyVar);

and inside my native, I can read the content of MyVar, with :

std::string(duk_to_string(ctx, 0));

but, I need to modify the value of this variable inside native function. what is the best way for does it? (I can't use the return statement) thanks.

jerome
  • 3
  • 1

1 Answers1

0

That's not possible as it would implement pass-by-reference (which is not supported in JS). Read also the answer to the question Pass Variables by Reference in Javascript

So, either pass in an object reference and change the object properties or use a return value.

Mike Lischke
  • 48,925
  • 16
  • 119
  • 181
  • Thank you, i become crazy when i searching the solution ( looking for duktape stack manipulation... ) , i will use the object properties , it's more easy. – jerome Jun 04 '17 at 16:04
  • If you find my answer helping you then pls accept it. – Mike Lischke Jun 04 '17 at 18:24