jurassic icon indicating copy to clipboard operation
jurassic copied to clipboard

Automatic conversion from C# to Jurassic JavaScript

Open immitev opened this issue 2 years ago • 2 comments

There is a relatively popular open-source conversion library from C# to VB.NET https://github.com/icsharpcode/CodeConverter . I wonder how easy or complex will be to have something similar for C# to Jurassic JS?

immitev avatar Sep 25 '23 11:09 immitev

It's probably not too difficult to convert the core C# language to JavaScript. (Harder than C# to VB.NET mind you.) But converting the .NET base class libraries (BCL) to the equivalent JavaScript standard library functions is basically an impossible task, because a) the BCL is huge, and b) there's lots of BCL functionality that simply doesn't exist in JavaScript. It might be possible if you restrict yourself to a subset of the BCL though.

paulbartrum avatar Sep 25 '23 12:09 paulbartrum

Indeed, the BCL is huge. I guess something more manageable will be as a default to use the BCL types/classes directly in the generated Jurassic code, and try to convert to pure JavaScript only some basic stuff.

Probably the code translator should be able to generate working JS code in plenty of scenarios, assuming there is available a helper function getClrType that can be used like this:

var File = getClrType('System.IO.File');
File.WriteAllText('C:\temp\test.txt', 'test');

immitev avatar Sep 25 '23 12:09 immitev