Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: How to pass short int from script to C# methods

0
0
I have the following code that fails with an exception:
    short myValue;
    public void SetValue(short v) {
        myValue = v;
    }
    void ClearScriptTest2(object sender, EventArgs e) {
        using (var engine = new V8ScriptEngine()) {
            engine.AddHostObject("Me", this);
            engine.Execute("Me.SetValue(123);");
            MessageBox.Show(myValue.ToString());
        }
    }
When I change the type of the parameter, v, for SetValue() from short to int, the code works.
It looks like Me.SetValue() expects a value of short type. So, my
question is: How do I call a method in script with parameter with type of short? Is there a way to let the script engine to convert a constant like "123" automatically to short?

Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles





Latest Images