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

New Post: How to use CLR enum in script?

$
0
0
Thanks for the detailed explanation.

IMO, Javascript is a weak/dynamic typing language and that's one of its attracting points as a script language. Casting is natural in C# but strange in Javascript. Enforcing strong typing is not what I'd expect in Javascript. If I've chosen strong typing, I'd take C# as script language and compile dynamically.

And I'm having another trouble which I think is also related to strong typing: I cannot call a CLR function with single precesion float parameters, because Javascript numbers are double. (Not 100% sure because I don't fully understand those dynamic binder code...)

For the enum value from keyEventArgs.KeyCode issue, I think there are still some confusion. My debugger shows the object type is System.Windows.Forms.Keys rather than HostObject, while print(Keys.Space) in script gives HostObject rather than "Space". So two differences from what you explained: 1) Enum values are not wrapped in HostObject in all scenarios; 2) Enum member's toString() does not give the enum member name but just [object HostObject].


I'm a bit frustrated for now. I don't know if these issues are related to my usage style. I'm calling Application.Run() for message loop in script, and scripts are called back though events for UI interaction. This is normal in C# but maybe not so well for script. I know some script engines have issues in such re-entrance usage scenario. I changed from Jint to ClearScript because Jint is really shitty at script error reporting, and Javascript.NET (which wrapps v8 too) does not support callbacks at all. Sorry for the rant...

Viewing all articles
Browse latest Browse all 2297

Trending Articles



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