Create a function with pass-by-value parameters


#1

I am currently trying to rip/replace an existing scripting engine in a legacy application with ChaiScript. One thing I have not been able to find a parallel for is creating functions with pass-by-value parameters. I have hunted the documentation, examples, and cheat-sheet, to no avail. As far as I can tell, every parameter in a function defined in the script is a pass-by-reference parameter.

Thanks,
Don


#2

You are correct - there is no parallel to pass-by-value in ChaiScript.

You can emulate it with clone if you need to, something like:

def myfunc(x, y, z)
{
  return myfunc_impl(clone(x), clone(y), clone(z));
}

def myfunc_impl(x, y, z)
{
  // do stuff with x,y,z
}

-Jason


#3

Thanks for the reply, that’s what I was afraid of. Workarounds are great for documentation, but less great for me trying to transcode customer scripts to the new syntax. Ah well, I’ll figure it out.

Thanks for the fast response!
Don