paulbartrum / jurassic

A .NET library to parse and execute JavaScript code.
MIT License
872 stars 121 forks source link

Feature Request: Unity3d support #35

Open Nanonid opened 8 years ago

Nanonid commented 8 years ago

I'm still diagnosing the issue but Jurrasic from asset store and from github both crash Unity3d. Somewhere in the IL code generation. I'm using Unity 5.4.0b20 (64-bit).

It's a pain, but the -unsafe and mono .net 2.0 is very limiting in JS choices.

Thanks.

tolstenko commented 8 years ago

You could generate the DLL from js using the function SaveDLL, and then import it. The problem is that the dll generated depends on the jurassic.dll and it has emit. It may be possible to generate a jurassic dll without the unsupported functions so it can be imported by unity and run the dll generated js code. Am I right?

paulbartrum commented 8 years ago

I haven't tested on Mono. I may do that at some point, but in the meantime, have you considered using Jint instead?

DAVco4 commented 8 years ago

I'm using Untiy 5.3.5f1 (latest stable) and Jurassic compiled for .NET Framework 3.5 with no issues. My IDE is VS2010, but I'm pretty sure that Unity compiles all it's code via Mono anyway.

This may be an issue with Unity 5.4?

tolstenko commented 8 years ago

@paulbartrum thanks for your suggestion. They use the keyword dynamic, which is currently unsupported by unity :/

The saved DLL depends on jurassic DLL, and jurassic uses emit which is unsupported on IL2CPP platforms such as iOS and WebGL. In order to use the saved DLL you must remove the jurassic dependency and/or stripe down all emit code from the jurassic.

This text describes the problem: https://developer.xamarin.com/guides/ios/advanced_topics/limitations/#No_Dynamic_Code_Generation

System.Reflection.Emit The lack of System.Reflection. Emit means that no code that depends on runtime code generation will work. This includes things like:

The Dynamic Language Runtime. Any languages built on top of the Dynamic Language Runtime. Remoting's TransparentProxy or anything else that would cause the runtime to generate code dynamically.

Important: Do not confuse Reflection.Emit with Reflection. Reflection.Emit is about generating code dynamically and have that code JITed and compiled to native code. Due to the limitations on the iPhone (no JIT compilation) this is not supported. But the entire Reflection API, including Type.GetType ("someClass"), listing methods, listing properties, fetching attributes and values works just fine.

Jayatubi commented 7 years ago

@DAVco4 How do you fix the compile issue when targeting .NET 3.5? I got an issue while the Jurassic using ConditionalWeakTable which was introduced in .NET 4.0

tolstenko commented 7 years ago

Unity announced that will support new mono compilers and new features -> http://forum.unity3d.com/threads/yes-unity-5-5-new-compiler-and-gc.408313/ But it targets only to 3.5. They need to modify lots of unity internal code to make 4.0 target working. You can check a almost stable build here: http://forum.unity3d.com/threads/upgraded-c-compiler-on-5-3-5p8.417363/ They have said the version 5.5 will address this compiler issue. I am waiting for it.

yosun commented 6 years ago

any update?

andywatts commented 6 years ago

Any tips on building this for unity?

yosun commented 6 years ago

pokes