ClearScript icon indicating copy to clipboard operation
ClearScript copied to clipboard

Question: try pattern from script

Open dementcore opened this issue 1 year ago • 1 comments

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!

dementcore avatar Mar 21 '24 16:03 dementcore

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!

ClearScriptLib avatar Mar 21 '24 16:03 ClearScriptLib

Please reopen this issue if you have additional thoughts or questions about this topic. Thank you!

ClearScriptLib avatar May 03 '24 03:05 ClearScriptLib