Can't receive multiple args from a JS function as 'params object[]' in C# #1796
Replies: 2 comments
-
Try using
|
Beta Was this translation helpful? Give feedback.
-
Thanks for the reply. You made me realize that no matter how I tried to do it with Funcs or Delegates, Engine.SetValue would always interpret a callable's params exactly how they're written in the code. A more detailed goal of mine was to grab callables out of a dictionary indexed by name and feed them into Engine.SetValue in such a way that when they're called from Javascript I could also pass some other arbitrary hidden stuff into them along with the variable number of params from JS, while also allowing them to have a return value that feeds back into JS. But with every attempt I was stuck with the method's expected params being either a hard object[] or the values I was trying to inject (which JS knows nothing about) + the params object[]. I've changed my design so that I'm just using Engine.SetValue with class methods directly that only accept params object[], which works, but makes it a little messier to register a ton of functions as each one needs to include identical code to get the hidden values passed in properly while also forwarding the params[]. But hey, it works for now. Thanks again :) |
Beta Was this translation helpful? Give feedback.
-
Hello there!
I'm trying to define an API inside of my C# app for my JS scripts to call. I've got that working, but now I'm trying to allow the JS to pass a variable number of arguments with these functions, and I can't seem to get it to work in an "automatic" way.
Take this example:
When I try to run this function in my script, as such:
I'm met with a JavascriptException: Value of object[] type is expected, but actual type is System.String. However, if I send those arguments inside of an array, it works (but I don't want to have to do that). In addition, if I send an array, any further arguments after the array are ignored. I've tried this same basic example using Funcs instead of delegates also, same result.
My goal is to allow JS functions defined by the C# host app to send an arbitrary number of arguments of any type they want, at which point they'll be examined on a case by case basis inside the app (just like Javascript itself). I was under the assumption that Jint would automatically array-ify mutiple arguments from JS for me when sending them into .NET; is this not the case? How can I achieve this?
Beta Was this translation helpful? Give feedback.
All reactions