ClearScript
ClearScript copied to clipboard
Question: try pattern from script
Hi!
It is possible to invoke a host function with out parameters from script and get the value in script after invoke?
Example host code:
public int tryread(int count, out string result)
{
result = "Test";
return 10;
}
Example script code:
let variable= '';
var result = myhostobj.tryread(5,variable);
variable == 'Test'; //the host method invocation fills this script variable from the out parameter of tryread host method???
Thanks in advance!
Hi @dementcore,
You can use a host variable for this purpose.
First, you'll need a HostFunctions object:
engine.AddHostObject("host", new HostFunctions());
Once you have that, you can do the following in JavaScript:
let variable= host.newVar('');
var result = myhostobj.tryread(5,variable.out);
variable.value == 'Test'; // true
Good luck!
Please reopen this issue if you have additional thoughts or questions about this topic. Thank you!