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
Hi James2015Li,

Based on your comments, we've taken a closer look and decided to make some changes.

Ideally the engine should try to find Foo(int arg); then Foo(short arg), Foo(byte arg), Foo(sbyte), till it finds a match. I guess C/C++ uses this kind of promotion chain.

ClearScript uses the actual C# invocation binder (part of the C# compiler) to provide access to .NET methods using rules that are documented and well-understood. As you've discovered, however, some ambiguity and suboptimal behavior exists when numeric arguments are passed from script code.

We've identified a bug in ClearScript that breaks some scenarios for integer arguments, and we'll fix it in the next point release. That should make your original sample above (with the short parameter) work as expected. Unfortunately there's no simple solution for single-precision floating-point parameters, so explicit conversion via host.toSingle() will continue to be required for float binding from JavaScript.

Unfortunately, the above sample code fails when you change the [field] data type from "short" to "float":

Yes, that's another bug. The next point release will relax the rules for numeric field and property assignment, allowing lossy conversion to take place implicitly.

Thank you very much for reporting these issues!

Viewing all articles
Browse latest Browse all 2297

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>