Giter Club home page Giter Club logo

unityscript2csharp's Introduction

What is this

A tool to help the conversion from UnityScript -> C#

You can read more about in this blog post.

Where can I get help?

If you hit any issues or have any questions feel free to send a message in the conversion forum thread: https://forum.unity.com/threads/unityscript-2-csharp-conversion-tool.487753/

How to use

First, download the tool from here.

Before running the conversion tool:

  1. Backup your project

  2. Keep in mind that you'll have best results (i.e, a smoother conversion process) if your UnityScripts have #pragma strict applied to them.

  3. Launch Unity editor (2017.3 ~ 2018.1.x versions are supported; latest 2018.1.x is recommended) and make sure you allow APIUpdater to run and update any obsolete API usages. This is necessary to avoid compilation errors during the conversion.

Next step is to run the converter. For that we recomend trying the Editor Unity Package Integration first:

  1. Install the package (downloaded from here)
  2. Select Tools/Convert Project from UnityScript to C#
  3. Follow the steps.

If you need more control over the options used during the conversion, you can use the application (UnityScript2CSharp.exe) passing the path to the project (-p) the Unity root installation folder (-u) and any additional assembly references (-r) used by the UnityScript scripts. Bellow you can find a list of valid command line arguments and their meaning:

Argument Meaning
-u, --unityPath Required. Unity installation path.
-p, --projectPath Required. Path of project to be converted.
-r, --references Assembly references required by the scripts (space separated list).
-g, --gameassemblies References previously built game assemblies (Assembly-*-firstpass.dll under Library/).
-s, –symbols A (comma separated) list of custom symbols to be defined.
-o, –deleteOriginals Deletes original files (default is to rename to .js.old)
-d Dumps out the list of scripts being processed
-i Ignore compilation errors. This allows the conversion process to continue instead of aborting.
--skipcomments (Default: False) Do not try to preserve comments (Use this option if processing comments cause any issues).
--showorphancomments Show a list of comments that were not written to the converted sources (used to help identifying issues with the comment processing code).
-v, –verbose Show verbose messages
-n, –dry-run Run the conversion but do not change/create any files on disk.
–help Display this help screen.

Example:

UnityScript2CSharp.exe -p m:\Work\Repo\4-0_AngryBots -u M:\Work\Repo\unity\build -r "m:\AngryBot Assemblies\Assembly-CSharp.dll" "m:\AngryBot Assemblies\Assembly-UnityScript.dll" -s UNITY_ANDROID,UNITY_EDITOR

Limitations

  • Some comments may not be preserved or be misplaced.

  • Guarded code (#if … )

    • UnityScript parser simply ignores guarded code when the condition evaluates to false leaving no traces of the original code when we are visiting the generated AST. The alternative for now is to run the tool multiple times in order to make sure all guarded code will eventually be processed. Each time the tool is executed user is required to merge the generated code manually.
  • Formatting is not preserved

  • UnityScript.Lang.Array (a.k.a Array) methods are not fully supported. We convert such type to object[] (this means that if your scripts relies on such methods you'll need to replace the variable declarations / instantiation with some other type (like List, Stack, etc) and fix the code.

  • Type inference in anonymous function declarations are inaccurate in some scenarios and may infer the wrong parameter / return type.

  • Local variable scope sometimes gets messed up due to the way UnityScript scope works.

  • Types with hyphens in the name (like This-Is-Invalid) are converted as as-it-is but they are not valid in C#

  • Missing return values are not inject automatically (i.e, on a non void method, a return; statement will cause a compilation error in the converted code)

  • Automatic conversion from object to int/long/float/bool etc is not supported (limited support for int -> bool conversion in conditional expressions is in place though).

  • for( init; condition; increment) is converted to while

  • Methods with same name as the declaring class (invalid in C#) are converted as-it-is

  • Invalid operands to as operators (which always yield null in US) are considered errors by the C# compiler.

  • Equality comparison against null used as statement expressions generate errors in C# (eg: foo == null;) (this code in meaningless, but harmless in US)

  • Code that changes foreach loop variable (which is not allowed in C#) are converted as-is, which means the resulting code will not compile cleanly.

  • Not supported features

    • Property / Event definition
    • Macros
    • Literals
      • Regular expressions

Note that any unsupported language construct (a.k.a, AST node type), will inject a comment in the converted source including the piece of code that is not supported and related source/line information.

How to build

In case you want to build the tool locally, "all" you need to do is:

  1. Clone the repository
  2. In a console, change directory to the cloned repo folder
  3. Restore nuget packages (you can download nuget here) -- run nuget.exe restore
  4. Build using msbuild -- msbuild UnityScript2CSharp.sln /target:clean,build

How to run tests

All tests (in UnityScript2CSharp.Tests.csproj project) can be run with NUnit runner (recommended to use latest version).

Windows

If you have Unity installed most likely you don't need any extra step; in case the tests fail to find Unity installation you can follow steps similar to the ones required for OSX/Linux

OSX / Linux

The easiest way to get the tests running is by setting the environment variable UNITY_INSTALL_FOLDER to point to the Unity installation folder and launch Unit rest runner.

FAQ

Q: During conversion, the following error is shown in the console:

"Conversion aborted due to compilation errors:"

And then some compiler errors complaining about types not being valid.

A: You are missing some assembly reference; if the type in question is define in the project scripts it is most likely Assembly-CSharp.dll or Assembly-UnityScript.dll (just run the conversion tool again passing -r path_to_assembly_csharp path_to_assembly_unityscript as an argument.


Q: Some of my UnityScript code is not included in the converted CSharp

A: Most likely this is code guarded by SYMBOLS. Look for **#if ** / #else directives in the original UnityScript and run the conversion tool passing the right symbols. Note that in some cases one or more symbols may introduce mutually exclusive source snippets which means that no matter if you specify the symbol or not, necessarily some region of the code will be excluded, as in the example:

#if !SYMBOL_1
// Snippet 1
#endif

#if SYMBOL_1
// Snippet 2
#endif

In the example above, if you run the conversion tool specifying the symbol SYMBOL_1 , Snippet 1 will be skipped (because it is guarded by a !SYMBOL_1) and Snippet 2 will be included. If you don't, Snippet 1 will be included but Snippet 2 will not (because SYMBOL_1 is not defined).

The best way to workaround this limitation is to set-up a local VCS repository (git, mercurial or any other of your option) and run the conversion tool with a set of symbols then commit the generated code, revert the changes to the UnityScript scripts (i.e, restore the original scripts), run the conversion tool again with a different set of Symbols and merge the new version of the converted scripts.


unityscript2csharp's People

Contributors

adrianoc avatar adrianoc-unity3d avatar richard-fine avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unityscript2csharp's Issues

“try/catch" is not support yet?

try {
	VetP = GetComponent.<Pjson>().getModelByName(TheJson,Cscript.Right_node[ii].name);
	Cscript.Right_node[ii].localPosition = VetP;
	print("Right_node["+ii+"].localPosition"+Cscript.Right_node[ii].name+VetP);
} catch (e) {
	print("++++Error+Right+"+Cscript.Right_node[ii].name);
}

got converted as

/* Node type not supported yet 
try:
	VetP = self.GetComponent[of Pjson]().getModelByName(TheJson, Cscript.Left_node[ii].name)
	Cscript.Left_node[ii].localPosition = VetP
	UnityEngine.MonoBehaviour.print((((('Left_node[' + ii) + '].localPosition') + Cscript.Left_node[ii].name) + VetP))
except e as System.Exception:
	UnityEngine.MonoBehaviour.print(('++++Error+left+' + Cscript.Left_node[ii].name))

@I:\unity\FaceHairMakerLocal2017b\Assets\scripts\data\io\SaveModelScript.js(249,9)*/
            {
                Vector3 VetP = this.GetComponent<Pjson>().getModelByName(TheJson, Cscript.Left_node[ii].name);
                //CoverText.text = "z2a"+ii+"x"+VetP;
                Cscript.Left_node[ii].localPosition = VetP;
                MonoBehaviour.print(((("Left_node[" + ii) + "].localPosition") + Cscript.Left_node[ii].name) + VetP);
            }
            /* Node type not supported yet 
except e as System.Exception:
	UnityEngine.MonoBehaviour.print(('++++Error+left+' + Cscript.Left_node[ii].name))

@I:\unity\FaceHairMakerLocal2017b\Assets\scripts\data\io\SaveModelScript.js(255,11)*/System.Exception e
         {
                //CoverText.text = "z2a"+ii+"\ne:"+e.message;
                MonoBehaviour.print("++++Error+left+" + Cscript.Left_node[ii].name);
         }

Error CS0234 (missing type/namespace) in Unity 5.6.6f2

Documentation here says Unity 5.6.x is preferred, but in Unity 5.6.6f2 I receive this error message after importing the package:

Assets/UnityScript2CSharp/Editor/UnityScript2CSharpRunner.cs(9,19): error CS0234: The type or namespace name `Compilation' does not exist in the namespace `UnityEditor'. Are you missing an assembly reference?

Opening the same project in Unity 2017.4.2f removes the error message. So maybe you should recommend Unity 2017.x instead of 5.6.x?

Failed to convert: CompilationPipeline.cs:44 error

On Unity 2018.1.2f1 -
Got this error:
NullReferenceException: Object reference not set to an instance of an object
UnityEditor.Compilation.Assembly.<get_allReferences>m__0 (UnityEditor.Compilation.Assembly a) (at C:/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/CompilationPipeline.cs:44)
System.Linq.Enumerable+SelectArrayIterator2[TSource,TResult].MoveNext () (at <839a3cb835c04d14aeb58d83bb7bc4bd>:0) System.Collections.Generic.EnumerableHelpers.IterativeCopy[T] (System.Collections.Generic.IEnumerable1[T] source, T[] array, System.Int32 arrayIndex, System.Int32 count) (at <839a3cb835c04d14aeb58d83bb7bc4bd>:0)
System.Collections.Generic.EnumerableHelpers.Copy[T] (System.Collections.Generic.IEnumerable1[T] source, T[] array, System.Int32 arrayIndex, System.Int32 count) (at <839a3cb835c04d14aeb58d83bb7bc4bd>:0) System.Linq.Enumerable+Concat2Iterator1[TSource].ToArray () (at <839a3cb835c04d14aeb58d83bb7bc4bd>:0)
System.Linq.Enumerable.ToArray[TSource] (System.Collections.Generic.IEnumerable1[T] source) (at <839a3cb835c04d14aeb58d83bb7bc4bd>:0) UnityEditor.Compilation.Assembly.get_allReferences () (at C:/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/CompilationPipeline.cs:44) UnityScript2CSharpRunner.ReferencesFromAssembly (UnityEditor.Compilation.Assembly a) (at Assets/UnityScript2CSharp/Editor/UnityScript2CSharpRunner.cs:294) System.Linq.Enumerable+SelectManySingleSelectorIterator2[TSource,TResult].MoveNext () (at <839a3cb835c04d14aeb58d83bb7bc4bd>:0)
System.Linq.Enumerable+WhereEnumerableIterator1[TSource].MoveNext () (at <839a3cb835c04d14aeb58d83bb7bc4bd>:0) System.Linq.Enumerable+DistinctIterator1[TSource].MoveNext () (at <839a3cb835c04d14aeb58d83bb7bc4bd>:0)
UnityScript2CSharpRunner.ComputeConverterCommandLineArguments (System.Boolean verboseLogging) (at Assets/UnityScript2CSharp/Editor/UnityScript2CSharpRunner.cs:268)
UnityScript2CSharpRunner.RunConverter (System.String converterPath) (at Assets/UnityScript2CSharp/Editor/UnityScript2CSharpRunner.cs:180)
UnityScript2CSharpRunner.Convert () (at Assets/UnityScript2CSharp/Editor/UnityScript2CSharpRunner.cs:97)

What can it be?
Thank you

Not compatible with Unity 2018.2(+)

Version 2018.1 is the most recent version supported, but there are many more recent versions now.
I've got Unity 2018.2.18f1, for instance, and therefore my project is already irreversibly updated past the supported version. The package suggests using a supported version, but I don't see how I can follow that suggestion if I can't open my project in an earlier version.

Is there any intention of supporting newer versions?

Do not emit lambda parameter types if C# compiler can infer them

Given a method (in C#) like:

void M(Func<int, int> f) {}

The following UnityScript code

M( function (i) return i + 1);

is converted to:

M( (object i) => return i + 1);

Which is wrong.

Also in this case the C# compiler can infer the types of i, so instead we should convert it to:

M(  (i) => return i + 1);

`using UnityEditor;` should not be added by default to all converted scripts

Currently, all converted scripts have the following included at the very beginning:

using UnityEngine;
using UnityEditor;
using System.Collections;

using UnityEditor; should only be included if the generated script is in an Editor folder or if any Editor only API is surrounded by #if UNITY_EDITOR #endif. Otherwise, building a project with scripts like this for any platform is going to fail because UnityEditor cannot be found.

converting multiple assigments in same statemets failed

    meta.transform.localScale.y=meta.transform.localScale.z= meta.transform.localScale.x;

got converted as

    {
        float _295 = ;
        Vector3 _296 = this.meta.transform.localScale;
        _296.y = _295this.meta.transform.localScale = _296;
    }

Switchs mixing int and enums in condition / cases are not converted

Test Switch_With_Int_Expression_As_Condition_And_Enum_As_Comparisons result

Converted:
using UnityEngine; using System.Collections; public enum E { A = 0, B = 1 } [System.Serializable] public partial class switch_int_enum : MonoBehaviour { public virtual int F(int i) { { $switch$1 = i; if (((E) $switch$1) >== E.A) { return 1; } if (((E) $switch$1) == E.B) { return 2; } } return 0; } }

Expected string length 269 but was 299. Strings differ at index 183.
Expected: "...public virtual int F(int i) { switch ((E) i) { case E.A: r..."
But was: "...public virtual int F(int i) { { $switch$1 = i; if (((E) $s..."

missing new keyword and nullcheck

Using 1.0.7003.16529 from command line. with -v -i -d params.

Theres a third party librarry in the plugins folder LitJson.
https://github.com/LitJSON/litjson

JS Source

#pragma strict

import LitJson;

function Start () 
{
    var jsonData : JsonData = new JsonData();
    if(jsonData)
    {

    }

}

Output

using LitJson;
using UnityEngine;
using System.Collections;

[System.Serializable]
public partial class Test_JS_LitJson : MonoBehaviour
{
    public virtual void Start()
    {
        JsonData jsonData = JsonData();
        if (jsonData)
        {
        }
    }
}

console output

Assets/Scripts/Test/Test_LitJson/Test_JS_LitJson.cs(10,29): error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected

Assets/Scripts/Test/Test_LitJson/Test_JS_LitJson.cs(11,9): error CS0266: Cannot implicitly convert type `LitJson.JsonData' to `bool'. An explicit conversion exists (are you missing a cast?)

Array Clear and Array Contains

using UnityScript2CSharp_1.0.7002.42237

I know about the limitation however, i would like to ask some guidence in the matter.

The original JS code

public enum CameraFlag
{
    Animated = 0,
    ContinuousUpdate = 1,
    SwitchOnly = 2,
    PositionZoomable = 3,
    FieldOfViewZoomable = 4,
    OrthographicZoomable = 5,
    JoystickNavigated = 6
}

protected CameraFlag[] flags;

protected function AddFlag(flag : CameraFlag)
{
	if (!(flag in flags))
		flags += [flag];
}

protected function ClearFlags()
{
	flags = [];
}

protected function HasFag(flag : CameraFlag) : boolean
{
     return flag in this.flags
}

The converters result c# code

protected virtual void ClearFlags()
{
       this.flags = new null[] {};
}

protected virtual void AddFlag(CameraFlag flag)
{
   if (!(flag in ((CameraFlag)this.flags)))
   {
       this.flags = (CameraFlag[]) Boo.Lang.Runtime.RuntimeServices.AddArrays(typeof(CameraFlag), this.flags, new CameraFlag[] {flag});
  }
}

protected virtual bool HasFag(CameraFlag flag)
{
     return flag in (CameraFlag)this.flags;
}

Suggesting a correction using Array Clear

protected virtual void ClearFlags()
{
   System.Array.Clear(this.flags, 0, this.flags.Length);
}

Suggesting a correction using Generic Collection Clear

protected virtual void ClearFlags()
{
   this.flags.Clear();
}

Suggesting a correction using Array Exists

protected virtual void AddFlag(CameraFlag flag)
{
   if(!System.Array.Exists(this.flags, e => e == flag))
   {
        this.flags = (CameraFlag[]) Boo.Lang.Runtime.RuntimeServices.AddArrays(typeof(CameraFlag), this.flags, new CameraFlag[] {flag});
   }
}

Suggestion a correction using Array Contains from Linq

protected virtual bool HasFag(CameraFlag flag)
{
     return flags.Contains(flag);
}

Command window automatically closes when opened.

Hello,

I have downloaded the files and followed the instructions. However whenever I try to use the "UnityScript2CSharp.exe", it starts the command window only to close it shortly after. It closes so fast that I don't have time to write in any commands to it.
My computer is running a Windows 7 and my version of Unity is Unity 5.6.1f1.

Repro:

  • Download the tool from here: https://github.com/Unity-Technologies/unityscript2csharp/releases
    (Version UnityScript2CSharp_1.0.6458.18187.zip)
  • Extract the UnityScript2CSharp_1.0.6458.18187.zip file in a folder.
  • Launch a new unity project.
  • Create a JS script named Test.js with the following code in it:
    #pragma strict
    function Update () {
    if(Input.GetKeyDown("a")){
    print("Hello");
    }
    }
  • Make sure that the Anti-virus program has not blocked "UnityScript2CSharp.exe".
  • Launch the "UnityScript2CSharp.exe" file.
    [Edit: launched the .exe file by double clicking on it]

Expected: A command window to open when launching the "UnityScript2CSharp.exe" file and to be able to convert the Test.js script to a Test.cs script.
Actual: Opens and closes the command window within 1-2 seconds automatically and the Test.js is not converted to CSharp.

String.length -> string.Length

Using 1.0.7003.16529 from command line. with -v -i -d params.

js code

class SomeClass extends MonoBehaviour {
	var decimalPrecision : int = 4;
	var time : float;
	var numberText : kText2D[] = new kText2D[0];
	var prefixText : kText2D[] = new kText2D[0];
	var postfixText : kText2D[] = new kText2D[0];
	
	function Start () {
		
	}

	function Update () {
		var scale : float = Mathf.Pow(10.0, decimalPrecision);
		var roundedTime : float = Mathf.Round(time * scale) / scale;
		var numberString : String = roundedTime + '';
		var decimalPointPosition : int = numberString.IndexOf('.');
		if(decimalPointPosition == -1){
			numberString += '.';
			decimalPointPosition = numberString.IndexOf('.');
		}
		if(decimalPointPosition > -1){
			while(numberString.length - decimalPointPosition <= decimalPrecision){
				numberString += '0';
			}
		}
	}
}

Result

using UnityEngine;
using System.Collections;

[System.Serializable]
public class SomeClass : MonoBehaviour
{
    public int decimalPrecision;
    public float time;
    public kText2D[] numberText;
    public kText2D[] prefixText;
    public kText2D[] postfixText;
    public virtual void Start()
    {
    }

    public virtual void Update()
    {
        int i = 0;
        float scale = Mathf.Pow(10f, this.decimalPrecision);
        float roundedTime = Mathf.Round(this.time * scale) / scale;
        string numberString = roundedTime + "";
        int decimalPointPosition = numberString.IndexOf(".");
        if (decimalPointPosition == -1)
        {
            numberString = numberString + ".";
            decimalPointPosition = numberString.IndexOf(".");
        }
        if (decimalPointPosition > -1)
        {
            while ((numberString.length - decimalPointPosition) <= this.decimalPrecision)
            {
                numberString = numberString + "0";
            }
        }
        i = 0;
        }
}

where the String.length not have been replaced by string.Length

better way to determine which file caused the error

Tried with Unity Editor Tool. Current latest
(UnityScript2CSharp_Conversion_1.0.6998.28881.unitypackage)

i had 302 script files in the project and i have no clue which file caused it.

in the output the only thing i see

`Defined Symbols:
Internal compiler error: Object reference not set to an instance of an object..

at Boo.Lang.Compiler.Ast.DepthFirstVisitor.OnError(Node node, Exception error) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\DepthFirstVisitor.cs:line 83
at Boo.Lang.Compiler.Ast.DepthFirstVisitor.Visit(Node node) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\DepthFirstVisitor.cs:line 55
at Boo.Lang.Compiler.Ast.DepthFirstVisitor.Visit(Node[] array) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\DepthFirstVisitor.cs:line 112
at Boo.Lang.Compiler.Ast.DepthFirstVisitor.Visit[T](NodeCollection1 collection) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\DepthFirstVisitor.cs:line 119 at Boo.Lang.Compiler.Ast.DepthFirstVisitor.OnBlock(Block node) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\Impl\DepthFirstVisitor.cs:line 722 at UnityScript2CSharp.UnityScript2CSharpConverterVisitor.OnBlock(Block node) in G:\Work\repo\unityscript2csharp\UnityScript2CSharp\UnityScript2CSharpConverterVisitor.cs:line 496 at Boo.Lang.Compiler.Ast.Block.Accept(IAstVisitor visitor) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\Impl\BlockImpl.cs:line 69 at UnityScript2CSharp.UnityScript2CSharpConverterVisitor.OnMethod(Method node) in G:\Work\repo\unityscript2csharp\UnityScript2CSharp\UnityScript2CSharpConverterVisitor.cs:line 319 at Boo.Lang.Compiler.Ast.Method.Accept(IAstVisitor visitor) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\Impl\MethodImpl.cs:line 75 at UnityScript2CSharp.UnityScript2CSharpConverterVisitor.WriteMembersOf(TypeDefinition node) in G:\Work\repo\unityscript2csharp\UnityScript2CSharp\UnityScript2CSharpConverterVisitor.cs:line 1553 at UnityScript2CSharp.UnityScript2CSharpConverterVisitor.OnClassDefinition(ClassDefinition node) in G:\Work\repo\unityscript2csharp\UnityScript2CSharp\UnityScript2CSharpConverterVisitor.cs:line 174 at Boo.Lang.Compiler.Ast.ClassDefinition.Accept(IAstVisitor visitor) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\Impl\ClassDefinitionImpl.cs:line 67 at Boo.Lang.Compiler.Ast.DepthFirstVisitor.Visit(Node node) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\DepthFirstVisitor.cs:line 51 at Boo.Lang.Compiler.Ast.DepthFirstVisitor.Visit(Node[] array) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\DepthFirstVisitor.cs:line 112 at Boo.Lang.Compiler.Ast.DepthFirstVisitor.Visit[T](NodeCollection1 collection) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\DepthFirstVisitor.cs:line 119
at Boo.Lang.Compiler.Ast.DepthFirstVisitor.OnModule(Module node) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\Impl\DepthFirstVisitor.cs:line 240
at UnityScript2CSharp.UnityScript2CSharpConverterVisitor.OnModule(Module node) in G:\Work\repo\unityscript2csharp\UnityScript2CSharp\UnityScript2CSharpConverterVisitor.cs:line 146
at Boo.Lang.Compiler.Ast.Module.Accept(IAstVisitor visitor) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\Impl\ModuleImpl.cs:line 75
at Boo.Lang.Compiler.Ast.DepthFirstVisitor.Visit(Node node) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\DepthFirstVisitor.cs:line 51
at Boo.Lang.Compiler.Ast.DepthFirstVisitor.Visit(Node[] array) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\DepthFirstVisitor.cs:line 112
at Boo.Lang.Compiler.Ast.DepthFirstVisitor.Visit[T](NodeCollection1 collection) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\DepthFirstVisitor.cs:line 119 at Boo.Lang.Compiler.Ast.DepthFirstVisitor.OnCompileUnit(CompileUnit node) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\Impl\DepthFirstVisitor.cs:line 47 at Boo.Lang.Compiler.Ast.CompileUnit.Accept(IAstVisitor visitor) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\Impl\CompileUnitImpl.cs:line 69 at UnityScript2CSharp.UnityScript2CSharpConverter.Convert(IEnumerable1 inputs, IEnumerable1 definedSymbols, IEnumerable1 referencedAssemblies, Action3 onScriptConverted) in G:\Work\repo\unityscript2csharp\UnityScript2CSharp\UnityScript2CSharpConverter.cs:line 43 at UnityScript2CSharp.Program.ConvertScripts(AssemblyType assemblyType, IList1 scripts, UnityScript2CSharpConverter converter, CommandLineArguments args, List1 referencedSymbols, HashSet1 compilerErrors) in G:\Work\repo\unityscript2csharp\UnityScript2CSharp\Program.cs:line 344
at UnityScript2CSharp.Program.Main(String[] args) in G:\Work\repo\unityscript2csharp\UnityScript2CSharp\Program.cs:line 76`

Failure to convert using the latest version on 2017.4.21

Issue :
Converting on the v1.0.6991.18175 version of unityscript2csharp on Unity 2017.4.21f seems to give the following error, running from v1.0.6956.21054 doesn't appear to have this issues. The error cancels the porting process and leaves a nullpointer reference.

NullReferenceException: Object reference not set to an instance of an object
UnityEditor.Compilation.Assembly.<get_allReferences>m__0 (UnityEditor.Compilation.Assembly a) (at C:/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/CompilationPipeline.cs:26)
System.Linq.Enumerable+c__Iterator102[UnityEditor.Compilation.Assembly,System.String].MoveNext () System.Linq.Enumerable+<CreateConcatIterator>c__Iterator11[System.String].MoveNext ()
System.Collections.Generic.List1[System.String].AddEnumerable (IEnumerable1 enumerable) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:128)
System.Collections.Generic.List1[System.String]..ctor (IEnumerable1 collection) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:65)
System.Linq.Enumerable.ToArray[String] (IEnumerable1 source) UnityEditor.Compilation.Assembly.get_allReferences () (at C:/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/CompilationPipeline.cs:26) UnityScript2CSharpRunner.<ComputeConverterCommandLineArguments>m__1 (UnityEditor.Compilation.Assembly a) (at Assets/UnityScript2CSharp/Editor/UnityScript2CSharpRunner.cs:264) System.Linq.Enumerable+<CreateSelectManyIterator>c__Iterator122[UnityEditor.Compilation.Assembly,System.String].MoveNext ()
System.Linq.Enumerable+c__Iterator1D1[System.String].MoveNext () System.Linq.Enumerable+<CreateDistinctIterator>c__Iterator31[System.String].MoveNext ()
UnityScript2CSharpRunner.ComputeConverterCommandLineArguments (Boolean verboseLogging) (at Assets/UnityScript2CSharp/Editor/UnityScript2CSharpRunner.cs:268)
UnityScript2CSharpRunner.RunConverter (System.String converterPath) (at Assets/UnityScript2CSharp/Editor/UnityScript2CSharpRunner.cs:180)
UnityScript2CSharpRunner.Convert () (at Assets/UnityScript2CSharp/Editor/UnityScript2CSharpRunner.cs:97)

Specifications :
Unity 2017.4.21f, recently upgraded from 5.6.6f.
Running on Windows.

Steps to reproduce :
Install Unity Package, Go to Tools, Run Conversion Tool both the convert and verbose convert options seems to give this error.

3D int array not converted correctly.

Repro:

  • Add the following lines to a .js script:
function Test3DArray(){
	var myArray : int[,,];
	myArray = new int[10,10,10];
}
  • Then run the converter on the project.

Expected:

  • Expected the lines to be converted correctly to this:
public virtual void Test3DArray()
{
	int[,,] myArray = null;
	myArray = new int[10, 10, 10];
}

Actual:

  • It is instead converted to this:
public virtual void Test3DArray()
{
        int[,,] myArray = null;
        myArray = Boo.Lang.Builtins.matrix<int>(10, 10, 10);
}

Convertion fails when using curry function

Repro:

  • Add the following code to a .js script:
function Adapt(callback : function(int), value : int) : function()
{
	return function () { callback (value); };
}
  • Then run the converter on the project.

Expected: Converting the script without errors.

Actual: Does not convert any scripts.
Gives the error:
"Internal compiler error: Object reference not set to an instance of an object.."

The same error is given with or without the use of the (-i) command.

Conversion fails for function with "System.Type" parameter

Repro:

  • Add the following code to a .js file:
    /** Register Exported class name widget class. */ function registerClass( exportName:String, widgetClass:System.Type ) { }
  • Run converter on the project

Expected: Succeeds without errors
Actual: Generates correct code, but gives the error "Cannot find assembly: 'System'"

Full -v error

Cannot find assembly: 'System'

System.ApplicationException: Cannot find assembly: 'System'
at Boo.Lang.Compiler.CompilerParameters.LoadAssemblyFromLibPaths(String assembly, Boolean throwOnError)
at Boo.Lang.Compiler.CompilerParameters.ForName(String assembly, Boolean throwOnError)
at Boo.Lang.Compiler.CompilerParameters.LoadDefaultReferences()
at Boo.Lang.Compiler.CompilerParameters..ctor(IReflectionTypeSystemProvider reflectionProvider, Boolean loadDefaultReferences)
at UnityScript.UnityScriptCompilerParameters..ctor(IReflectionTypeSystemProvider reflectionTypeSystemProvider, Boolean loadDefaultReferences)
at UnityScript.UnityScriptCompilerParameters..ctor(Boolean loadDefaultReferences)
at UnityScript.UnityScriptCompilerParameters..ctor()
at UnityScript.UnityScriptCompiler..ctor()
at UnityScript2CSharp.UnityScript2CSharpConverter.CreatAndInitializeCompiler(IEnumerable1 inputs, IEnumerable1 definedSymbols, IEnumerable1 referencedAssemblies) in M:\Work\Repo\UnityScript2CSharp\UnityScript2CSharp\UnityScript2CSharpConverter.cs:line 68 at UnityScript2CSharp.UnityScript2CSharpConverter.Convert(IEnumerable1 inputs, IEnumerable1 definedSymbols, IEnumerable1 referencedAssemblies, Action3 onScriptConverted) in M:\Work\Repo\UnityScript2CSharp\UnityScript2CSharp\UnityScript2CSharpConverter.cs:line 28 at UnityScript2CSharp.Program.ConvertScripts(String scriptType, IList1 scripts, UnityScript2CSharpConverter converter, IEnumerable1 references, CommandLineArguments args, List1 referencedSymbols) in M:\Work\Repo\UnityScript2CSharp\UnityScript2CSharp\Program.cs:line 174
at UnityScript2CSharp.Program.Main(String[] args) in M:\Work\Repo\UnityScript2CSharp\UnityScript2CSharp\Program.cs:line 54

InvalidOperationException on supplying '-r' multiple times

Repro:

  • .\tool\UnityScript2CSharp.exe -p .\USTest\ -u "C:\Program Files\Unity 2017.2.0b6" -r "D:\scratchpad\US\USTest\Assets\uniSWF\DLLs\LibUniSWF.dll" -r "D:\scratchpad\US\USTest\Assets\uniSWF\DLLs\LibUniSWFInternal.dll"

Expected: If this is not supported, print the help message.
Actual:

Unhandled Exception: System.InvalidOperationException: Sequence contains more than one matching element at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable1 source, Func2 predicate) at CommandLine.Core.OptionMapper.<>c__DisplayClassa.<MapValues>b__0(SpecificationProperty pt) at System.Linq.Enumerable.<>c__DisplayClass7_03.b__0(TSource x)
at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext() at System.Linq.Enumerable.<ConcatIterator>d__581.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator1.MoveNext() at System.Linq.Enumerable.Aggregate[TSource,TAccumulate](IEnumerable1 source, TAccumulate seed, Func3 func) at CommandLine.Core.ReflectionExtensions.SetProperties[T](T instance, IEnumerable1 specProps, Func2 predicate, Func2 selector)
at CommandLine.Core.InstanceBuilder.Build[T](Func1 factory, Func3 tokenizer, IEnumerable1 arguments, StringComparer nameComparer, CultureInfo parsingCulture) at CommandLine.Parser.<>c__DisplayClass41.b__2()
at CommandLine.Parser.MakeParserResult[T](Func1 parseFunc, ParserSettings settings) at CommandLine.Parser.ParseArguments[T](Func1 factory, String[] args)
at CommandLine.Parser.ParseArguments[T](String[] args)
at UnityScript2CSharp.Program.Main(String[] args) in M:\Work\Repo\UnityScript2CSharp\UnityScript2CSharp\Program.cs:line 16`

Comparator function

Using UnityScript2CSharp_1.0.7002.42237

Original JS Code

public function AttachCamerasAutomatically()
{
	var tempCameras : kCameraControl[] = new kCameraControl[0];
	tempCameras = GameObject.FindObjectsOfType(kCameraControl);
	if (tempCameras.length > 0) {
		cameras = [];  
		kUtils.SelectionSort(tempCameras, CompareCameraNames); // ABC order
		var i : int;
		for(i = 0; i < tempCameras.Length; i++){
			if(tempCameras[i].name != kConstants.LOADER_CAMERA_OBJECT){
				cameras += [tempCameras[i]];
			}
		}
	}			 		
}

private var CompareCameraNames = function(item1 : Object, item2 : Object) : int
{
	return String.Compare((item1 as kCameraControl).gameObject.name, (item2 as kCameraControl).gameObject.name, true);
};

Converter result c# Code

public virtual void AttachCamerasAutomatically()
{
    int i = 0;
    kCameraControl[] tempCameras = new kCameraControl[0];
    tempCameras = (kCameraControl[]) GameObject.FindObjectsOfType(typeof(kCameraControl));
    if (tempCameras.Length > 0)
    {
        this.cameras = new null[] {};
        kUtils.SelectionSort(tempCameras, this.CompareCameraNames); // ABC order
        i = 0;
        while (i < tempCameras.Length)
        {
            if (tempCameras[i].name != kConstants.LOADER_CAMERA_OBJECT)
            {
                this.cameras = (kCameraControl[]) Boo.Lang.Runtime.RuntimeServices.AddArrays(typeof(kCameraControl), this.cameras, new kCameraControl[] {tempCameras[i]});
            }
            i++;
        }
    }
}

private Func<object,object,int> CompareCameraNames;

Where Func is unknow because System is not included before.
And the whole logic of the comparator function is missing.

.Net framework 4.6.2 required?

image

Hi. I run Windows 10, our corporate policy means we run under 4.6.1 and will for the forseeable.
Is building against 4.6.2 "required" internally in some way? some feature of it important over building for 4.6.1?

Anyway, thought I would ask. Since 5.6.x directs me to use the command line without checking the .net version. then the command line version also fails.

Doesn't look good. thanks

Conversion fails on yield statements

I'm running conversion on a older project, with command
UnityScript2CSharp.exe -p D:\Unity\SWC_Android -u D:\Unity\Unity5.6.2f1 -s UNITY_ANDROID,UNITY_EDITOR -d -v -n
on
UnityScript2CSharp_1.0.6549.34518.

"yield w;" is always failed on with invalid cast error, where w is WWW object

D:\Unity\SWC_Android\Assets_SWC_scripts\controlers\gamemaster.js(1305,11): BCE0055: Internal compiler error: Unable to cast object of type 'Boo.Lang.Compiler.TypeSystem.Internal.InternalLocal' to type 'Boo.Lang.Compiler.TypeSystem.IType'..
System.InvalidCastException: Unable to cast object of type 'Boo.Lang.Compiler.TypeSystem.Internal.InternalLocal' to type 'Boo.Lang.Compiler.TypeSystem.IType'.
at UnityScript2CSharp.Steps.InjectTypeOfExpressionsInArgumentsOfSystemType.OnReferenceExpression(ReferenceExpression node) in D:\Work\repo\unityscript2csharp\UnityScript2CSharp\Steps\InjectTypeOfExpressionsInArgumentsOfSystemType.cs:line 45
at Boo.Lang.Compiler.Ast.ReferenceExpression.Accept(IAstVisitor visitor) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\Impl\ReferenceExpressionImpl.cs:line 69
at Boo.Lang.Compiler.Ast.DepthFirstTransformer.OnNode(Node node) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\DepthFirstTransformer.cs:line 54
at Boo.Lang.Compiler.Ast.DepthFirstTransformer.VisitNode(Node node) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\DepthFirstTransformer.cs:line 65
Consider running converter with '-i' option.

Execution fails with null reference exception

Unity 2018.1.0f2
https://github.com/Unity-Technologies/unityscript2csharp/tree/v1.0.7264.28836
.unitypackage version
Fails immediately after menu item tools/convert... with error, and no output.

NullReferenceException: Object reference not set to an instance of an object
UnityEditor.Compilation.Assembly.<get_allReferences>m__0 (UnityEditor.Compilation.Assembly a) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/CompilationPipeline.cs:44)
System.Linq.Enumerable+<CreateSelectIterator>c__Iterator10`2[UnityEditor.Compilation.Assembly,System.String].MoveNext ()
System.Linq.Enumerable+<CreateConcatIterator>c__Iterator1`1[System.String].MoveNext ()
System.Collections.Generic.List`1[System.String].AddEnumerable (IEnumerable`1 enumerable) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:128)
System.Collections.Generic.List`1[System.String]..ctor (IEnumerable`1 collection) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:65)
System.Linq.Enumerable.ToArray[String] (IEnumerable`1 source)
UnityEditor.Compilation.Assembly.get_allReferences () (at /Users/builduser/buildslave/unity/build/Editor/Mono/Scripting/ScriptCompilation/CompilationPipeline.cs:44)
UnityScript2CSharpRunner.ReferencesFromAssembly (UnityEditor.Compilation.Assembly a) (at Assets/UnityScript2CSharp/Editor/UnityScript2CSharpRunner.cs:295)
System.Linq.Enumerable+<CreateSelectManyIterator>c__Iterator12`2[UnityEditor.Compilation.Assembly,System.String].MoveNext ()
System.Linq.Enumerable+<CreateWhereIterator>c__Iterator1D`1[System.String].MoveNext ()
System.Linq.Enumerable+<CreateDistinctIterator>c__Iterator3`1[System.String].MoveNext ()
UnityScript2CSharpRunner.ComputeConverterCommandLineArguments (Boolean verboseLogging) (at Assets/UnityScript2CSharp/Editor/UnityScript2CSharpRunner.cs:269)
UnityScript2CSharpRunner.RunConverter (System.String converterPath) (at Assets/UnityScript2CSharp/Editor/UnityScript2CSharpRunner.cs:181)
UnityScript2CSharpRunner.Convert () (at Assets/UnityScript2CSharp/Editor/UnityScript2CSharpRunner.cs:98)

Internal compiler errror with shortcut *null check* in chainned condition

function Foo(mb: MonoBehaviour, bb : boolean) { return (mb && mb.enabled && bb); }
Above UnityScript code causes converter to crash.
Most likely issue with PromoteImplicitBooleanConversionsToExplicitComparisons

Callstack:

Boo.Lang.Compiler.CompilerError : Internal compiler error: Object reference not set to an instance of an object..
----> System.NullReferenceException : Object reference not set to an instance of an object.
at Boo.Lang.Compiler.Ast.DepthFirstVisitor.OnError(Node node, Exception error) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\DepthFirstVisitor.cs:line 83
at Boo.Lang.Compiler.Ast.DepthFirstVisitor.Visit(Node node) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\DepthFirstVisitor.cs:line 55
at Boo.Lang.Compiler.Ast.DepthFirstVisitor.Visit(Node[] array) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\DepthFirstVisitor.cs:line 112
at Boo.Lang.Compiler.Ast.DepthFirstVisitor.Visit[T](NodeCollection1 collection) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\DepthFirstVisitor.cs:line 119 at Boo.Lang.Compiler.Ast.DepthFirstVisitor.OnBlock(Block node) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\Impl\DepthFirstVisitor.cs:line 722 at UnityScript2CSharp.UnityScript2CSharpConverterVisitor.OnBlock(Block node) in G:\Work\repo\unityscript2csharp\UnityScript2CSharp\UnityScript2CSharpConverterVisitor.cs:line 497 at Boo.Lang.Compiler.Ast.Block.Accept(IAstVisitor visitor) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\Impl\BlockImpl.cs:line 69 at UnityScript2CSharp.UnityScript2CSharpConverterVisitor.OnMethod(Method node) in G:\Work\repo\unityscript2csharp\UnityScript2CSharp\UnityScript2CSharpConverterVisitor.cs:line 320 at Boo.Lang.Compiler.Ast.Method.Accept(IAstVisitor visitor) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\Impl\MethodImpl.cs:line 75 at UnityScript2CSharp.UnityScript2CSharpConverterVisitor.WriteMembersOf(TypeDefinition node) in G:\Work\repo\unityscript2csharp\UnityScript2CSharp\UnityScript2CSharpConverterVisitor.cs:line 1554 at UnityScript2CSharp.UnityScript2CSharpConverterVisitor.OnClassDefinition(ClassDefinition node) in G:\Work\repo\unityscript2csharp\UnityScript2CSharp\UnityScript2CSharpConverterVisitor.cs:line 175 at Boo.Lang.Compiler.Ast.ClassDefinition.Accept(IAstVisitor visitor) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\Impl\ClassDefinitionImpl.cs:line 67 at Boo.Lang.Compiler.Ast.DepthFirstVisitor.Visit(Node node) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\DepthFirstVisitor.cs:line 51 at Boo.Lang.Compiler.Ast.DepthFirstVisitor.Visit(Node[] array) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\DepthFirstVisitor.cs:line 112 at Boo.Lang.Compiler.Ast.DepthFirstVisitor.Visit[T](NodeCollection1 collection) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\DepthFirstVisitor.cs:line 119
at Boo.Lang.Compiler.Ast.DepthFirstVisitor.OnModule(Module node) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\Impl\DepthFirstVisitor.cs:line 240
at UnityScript2CSharp.UnityScript2CSharpConverterVisitor.OnModule(Module node) in G:\Work\repo\unityscript2csharp\UnityScript2CSharp\UnityScript2CSharpConverterVisitor.cs:line 147
at Boo.Lang.Compiler.Ast.Module.Accept(IAstVisitor visitor) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\Impl\ModuleImpl.cs:line 75
at Boo.Lang.Compiler.Ast.DepthFirstVisitor.Visit(Node node) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\DepthFirstVisitor.cs:line 51
at Boo.Lang.Compiler.Ast.DepthFirstVisitor.Visit(Node[] array) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\DepthFirstVisitor.cs:line 112
at Boo.Lang.Compiler.Ast.DepthFirstVisitor.Visit[T](NodeCollection1 collection) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\DepthFirstVisitor.cs:line 119 at Boo.Lang.Compiler.Ast.DepthFirstVisitor.OnCompileUnit(CompileUnit node) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\Impl\DepthFirstVisitor.cs:line 47 at Boo.Lang.Compiler.Ast.CompileUnit.Accept(IAstVisitor visitor) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\Impl\CompileUnitImpl.cs:line 69 at UnityScript2CSharp.UnityScript2CSharpConverter.Convert(IEnumerable1 inputs, IEnumerable1 definedSymbols, IEnumerable1 referencedAssemblies, Action3 onScriptConverted) in G:\Work\repo\unityscript2csharp\UnityScript2CSharp\UnityScript2CSharpConverter.cs:line 44 at UnityScript2CSharp.Tests.Tests.ConvertScripts(IList1 sourceFiles, String saveToFolder, Boolean verboseLog) in G:\Work\repo\unityscript2csharp\UnityScript2CSharp.Tests\Tests.Utilities.cs:line 107
at UnityScript2CSharp.Tests.Tests.TestCrash() in G:\Work\repo\unityscript2csharp\UnityScript2CSharp.Tests\Tests.cs:line 19
--NullReferenceException
at UnityScript2CSharp.UnityScript2CSharpConverterVisitor.<>c__DisplayClass64_0.b__0() in G:\Work\repo\unityscript2csharp\UnityScript2CSharp\UnityScript2CSharpConverterVisitor.cs:line 784
at UnityScript2CSharp.UnityScript2CSharpConverterVisitor.WrapWith(Boolean needParensAround, String prefix, String sufix, Action action) in G:\Work\repo\unityscript2csharp\UnityScript2CSharp\UnityScript2CSharpConverterVisitor.cs:line 1417
at UnityScript2CSharp.UnityScript2CSharpConverterVisitor.OnBinaryExpression(BinaryExpression node) in G:\Work\repo\unityscript2csharp\UnityScript2CSharp\UnityScript2CSharpConverterVisitor.cs:line 779
at Boo.Lang.Compiler.Ast.BinaryExpression.Accept(IAstVisitor visitor) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\Impl\BinaryExpressionImpl.cs:line 73
at UnityScript2CSharp.UnityScript2CSharpConverterVisitor.<>c__DisplayClass65_0.b__0() in G:\Work\repo\unityscript2csharp\UnityScript2CSharp\UnityScript2CSharpConverterVisitor.cs:line 806
at UnityScript2CSharp.UnityScript2CSharpConverterVisitor.WrapWith(Boolean needParensAround, String prefix, String sufix, Action action) in G:\Work\repo\unityscript2csharp\UnityScript2CSharp\UnityScript2CSharpConverterVisitor.cs:line 1417
at UnityScript2CSharp.UnityScript2CSharpConverterVisitor.OnConditionalExpression(ConditionalExpression node) in G:\Work\repo\unityscript2csharp\UnityScript2CSharp\UnityScript2CSharpConverterVisitor.cs:line 804
at Boo.Lang.Compiler.Ast.ConditionalExpression.Accept(IAstVisitor visitor) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\Impl\ConditionalExpressionImpl.cs:line 73
at UnityScript2CSharp.UnityScript2CSharpConverterVisitor.<>c__DisplayClass64_0.b__0() in G:\Work\repo\unityscript2csharp\UnityScript2CSharp\UnityScript2CSharpConverterVisitor.cs:line 788
at UnityScript2CSharp.UnityScript2CSharpConverterVisitor.WrapWith(Boolean needParensAround, String prefix, String sufix, Action action) in G:\Work\repo\unityscript2csharp\UnityScript2CSharp\UnityScript2CSharpConverterVisitor.cs:line 1417
at UnityScript2CSharp.UnityScript2CSharpConverterVisitor.OnBinaryExpression(BinaryExpression node) in G:\Work\repo\unityscript2csharp\UnityScript2CSharp\UnityScript2CSharpConverterVisitor.cs:line 779
at Boo.Lang.Compiler.Ast.BinaryExpression.Accept(IAstVisitor visitor) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\Impl\BinaryExpressionImpl.cs:line 73
at UnityScript2CSharp.UnityScript2CSharpConverterVisitor.<>c__DisplayClass64_0.b__0() in G:\Work\repo\unityscript2csharp\UnityScript2CSharp\UnityScript2CSharpConverterVisitor.cs:line 788
at UnityScript2CSharp.UnityScript2CSharpConverterVisitor.WrapWith(Boolean needParensAround, String prefix, String sufix, Action action) in G:\Work\repo\unityscript2csharp\UnityScript2CSharp\UnityScript2CSharpConverterVisitor.cs:line 1417
at UnityScript2CSharp.UnityScript2CSharpConverterVisitor.OnBinaryExpression(BinaryExpression node) in G:\Work\repo\unityscript2csharp\UnityScript2CSharp\UnityScript2CSharpConverterVisitor.cs:line 779
at Boo.Lang.Compiler.Ast.BinaryExpression.Accept(IAstVisitor visitor) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\Impl\BinaryExpressionImpl.cs:line 73
at UnityScript2CSharp.UnityScript2CSharpConverterVisitor.OnReturnStatement(ReturnStatement node) in G:\Work\repo\unityscript2csharp\UnityScript2CSharp\UnityScript2CSharpConverterVisitor.cs:line 621
at Boo.Lang.Compiler.Ast.ReturnStatement.Accept(IAstVisitor visitor) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\Impl\ReturnStatementImpl.cs:line 69
at Boo.Lang.Compiler.Ast.DepthFirstVisitor.Visit(Node node) in m:\Work\Repo\boo\src\Boo.Lang.Compiler\Ast\DepthFirstVisitor.cs:line 42

Converted code miss required cast to UnityEngine.Object

The following valid UnityScript code snippet

var obj:Object = GetUnityObjectInstance();
MethodTakingUnityObjectAsParameter( obj );

gets converted to:

object obj = GetUnityObjectInstance();
MethodTakingUnityObjectAsParameter( obj );

which is invalid since we are passing an object instance to a parameter typed as UnityEngine.Object (this works in UnityScript because the compiler emits the required cast in the generated IL).

Ideally the converted code should include this cast, thus the example above would be converted to:

object obj = GetUnityObjectInstance();
MethodTakingUnityObjectAsParameter( (UnityEngine.Object) obj ); // Notice the cast

Variable name string

Using UnityScript2CSharp_1.0.7002.42237

Original JS Code

function StringToBoolean(string : String) : boolean {
	return (string == '1');
}

Converted C# Code

public virtual bool StringToBoolean(string string)
{
    return string == "1";
}

Suggested Converted C# Code

public virtual bool StringToBoolean(string @string)
{
    return @string == "1";
}

Where the variable name conflicts with the C# primitive type

Strange behaviour when converting UnityScript Time.time

The following file will convert mostly fine except for C# line 51. The following issues occur

  • timetemp is declared as an Object when it should be a float

  • The if statement condition goes from (Time.time > timetemp + LifeTime) to((Time.time != 0f) > ((this.timetemp + this.LifeTime) != null))

Obviously this makes no sense, but it is easy to fix post import

Attached is the UnityScript, C# and meta for both:
Scripts.zip

private enum in js monobehaviour causes problem

private enum needs to stays inside monobehaviour class after conversion buts ends up outside C# class causing error

//js test
#pragma strict

private enum ETest {e1,e2,e3}

function Start () 
{

}

parseInt() / parseFloat() are converted to a method call in UnityScript.Lang.UnityBuiltins

This has been reported in Unity Forums: https://forum.unity.com/threads/unityscript-2-csharp-conversion-tool.487753/page-5#post-7418675

These methods have a couple of overloads taking string, int, single (floats) and doubles.

All overloads but the one taking a string should be replaced with a cast in a checked context (parseInt() => a checked cast to int and parseFloat() => a checked cast to float)

I think a good way to handle this by adding a new step to the converter (similar to
https://github.com/Unity-Technologies/unityscript2csharp/blob/master/UnityScript2CSharp/Steps/ReplaceUnityScriptArrayWithObjectArray.cs)

I tried to use the unitypackage inside the 2018 editor and get this error

I tried to use the unitypackage inside the 2018 osx editor and get this error:
Could not find file "/Applications/Unity/PlaybackEngines/LinuxStandaloneSupport/Variations/linux32_headless_development_mono/Data/Managed/UnityEditor.dll"

There is a file called UnityEngine.dll in that folder but not UnityEditor.dll

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.