2

I'm getting an exception when trying to use a decimal value with FunScript. It can be reproduced simply by using:

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

The exception says:

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)])

I suspect this is a FunScript limitation, but I just wanted to check. In that case, How could a decimal value be used in the context of FunScript code? Or How could Funscript be extended in order to fix this?

jruizaranguren
  • 12,679
  • 7
  • 55
  • 73

2 Answers2

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!

1

It is rather JavaScript limitation because JavaScript has only binary floating point. One of the solution would be creating your own type containing two integers: for integer part and fractional part

Petr
  • 4,280
  • 1
  • 19
  • 15