2

尝试在 FunScript 中使用十进制值时出现异常。它可以通过使用简单地复制:

Globals.window.alert(Globals.JSON.stringify(3M))

异常说:

System.Exception was unhandled
Message: An unhandled exception of type 'System.Exception' occurred in FunScript.dll
Additional information: Could not compile expression: Call (None, MakeDecimal,
      [Value (13), Value (0), Value (0), Value (false), Value (0uy)])

我怀疑这是 FunScript 的限制,但我只是想检查一下。在那种情况下,如何在 FunScript 代码的上下文中使用十进制值?或者如何扩展 Funscript 来解决这个问题?

4

2 回答 2

2

The decimal primitive is a TODO feature. I guess the best way to tackle it would be reimplementing the System.Decimal structure using the recently open sourced .NET Framework reference source and then add the appropiate expression replacements to the compiler like it's done for other types which do not translate directly from .NET to JavaScript like DateTime, TimeSpan, Regex, F# option or list, etc.

I guess the feature hasn't been prioritized. If you need it, can you please open an issue in the Github page so one of the contributors (maybe myself) can start implementing it? If you think you can do it yourself, please feel free to submit a pull request. Thanks!

于 2014-11-13T23:02:03.000 回答
1

这是相当 JavaScript 的限制,因为 JavaScript 只有二进制浮点。解决方案之一是创建自己的包含两个整数的类型:整数部分和小数部分

于 2014-11-13T13:37:44.363 回答