Problem running Jint inside Unity3d

Aug 12, 2011 at 8:50 PM

Hi all, I am trying to run Jint inside Unity3d (to access the game state, similar to the Unity C# REPL--- and am encountering the following difficulty using the current Jint 0.9.0 binary download.

The following simple test program correctly prints '6' when run at the command line using standalone Mono (2.6.7):

     Console.WriteLine(new JintEngine().Run("3+3"));

But when I try to call the similar code from inside a Unity script:

    Debug.Log(new JintEngine().Run("3+3"));

Unity goes into an infinite loop and needs to be killed.  Note that the Antlr3.Runtime.dll and Jint.dll are correctly placed in the Unity Assets/Plugins folder (as verified by next steps).   Looking at the Jint source code, I did some further research by starting with the first few steps of Run, i.e.,

   JintEngine engine = new JintEngine();
   Debug.Log("Engine created");
   var stream = new ANTLRStringStream("3+3");
   Debug.Log("Stream created");
   var lexer = new ES3Lexer(stream);
   Debug.Log("Lexer created");

Execution only gets as far as "Stream created" and then goes into an infinite loop in ES3Lexer call.   Any ideas?

Thanks in advance,


Aug 12, 2011 at 8:55 PM

IS it possible that unity is also using antlr, but another version of it ?

Aug 12, 2011 at 9:07 PM

I checked by googling "Unity Antlr" and also looked through the libraries in the Unity installation and didn't see any mention.   Any other ideas?  I guess my next move is to the Antlr forum?


Aug 12, 2011 at 9:09 PM

P.S. Which version (and target) of Antler is Jint 0.9.0 using?  It looks like there are more recent versions of Antlr3.Runtime.dll on the Antlr project site, but they are not necessarily compatible with current Jint code.

Aug 12, 2011 at 9:36 PM

I have updated to the latest one, but it's not yet a public release of jint. You can try using the latest source code maybe.

Aug 12, 2011 at 9:47 PM

Thanks for your quick reply!   Could you please be a bit more specific, however:

* Exactly what version of Antler are you referring to by "latest"?  Is it the Antlr 3.4 C# 3 runtime distribution at ?

* I would really appreciate if you would email me an updated Jint.dll.  It would reduce the possibility of my introducing some other problem by not compiling the system properly.

Thanks in advance, -CR

Email: rich at wpi dot edu

Aug 12, 2011 at 10:59 PM

Hi Sebastien,  Thanks for the try:  Same problem (and still works in standalone Mono 2.6).    I am pretty much out of ideas.


P.S. I spent a very pleasant week in Bordeaux earlier this summer for the Foundations of Digital Games conference (which I co-chaired).

Aug 12, 2011 at 11:03 PM

Don't know what can happen. Any change you could debug it ? Or have some logs to see where is the loop ?

Aug 12, 2011 at 11:50 PM

Unfortunately, Unity does not provide a way to interrupt an infinite loop (other than killing the whole application---many user complain about this!).   I guess I could go to the ES3Lexer source and start sprinking log prints in it (binary search) and recompile until I figure out where it goes away.  Not sure I have time to pursue this now.   Sigh...

Aug 15, 2011 at 9:38 PM

Hi Sebastien,

I recompiled Jint inside of Unity and found the following two small package-related problems.  I think both of these are "righteous changes" that you might want to make in source of next release:

(1) Remove "using System.Web;" from Jint/Native/JSGlobal.cs.   This package is not used in this file anyways, but referring to it causes a problem, as it is not available in standalone version of Unity.

(2) Remove the 5 definitions for Jint.Delegates.Func in JintEngine.cs and instead add System.Core to the packages referenced by the project.   These delegate definitions are redundant with those in System.Core (which is included in Unity) and thus causes an ambiguity for the compiler.

I am still having trouble accessing Unity methods from Jint (no problem with System methods), but will explain in separate communication.

Thanks for writing Jint!


Aug 15, 2011 at 9:54 PM

I also get some Func<> conflicts from time to time when I want to reference the source code from VS2010, I might change the name of those methods. But I don't want to remove them as it would break the 2.0 compatibility. Let's see also for System.Web ...