Search Unity

  1. We want you to join us at GDC this year! We've added new sessions to Unity Central, space is limited so sign up now!
    Dismiss Notice
  2. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  3. Unity 2017.3 has arrived! Read about it here.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Tell us about your experience here and you’ll get early access to the 2018 Game Studios report + more goodies.
    Dismiss Notice
  6. Be the first to take a peek at upcoming 2D Animation Preview. Drop into the forum and check it out!
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Facilities for script languages, Scheme in particular

Discussion in 'Wish List' started by hww, Feb 1, 2011.

  1. hww


    Nov 23, 2007
    I was not sure where to post this thread, scripting, support or wish list? Still do not know. Let's try it here.

    I love Lisp and Scheme. Of course I know that C# is good language, but Scheme is what I really like. The first thing I want to know about any game engine is, "How can it be used with Lisp or Scheme?"

    The first place where I checked for Unity is this forum. Result: almost nothing apropos. Then this page. And I think this interface is not useful for Scheme/Lisp implementations based on C or C++, because "Calling C# / JavaScript back from native code" will be slow. That is very bad because it limits scriptability to only infrequent high-level control. The ideal solution would be a fast interface, so a C-based Scheme like Gambit-C could be used for low-level operations like animation stacking, game object state controls, and so on.

    My next step was to check around for Scheme implementations on Mono. In my opinion, there is no perfect project for Mono yet. The IronScheme and Clojure NET looks most interesting. There are other Mono/CLR Scheme and Lisp implementations but IronScheme looks most usable right now.

    After some experiments I figured out that to get IronScheme I must compile it on my machine, which I did with MSVC. Then I copied IronScheme files to the Assets folder.

    Code (csharp):
    1. ironscheme.boot.dll
    2. IronScheme.Closures.dll
    3. IronScheme.dll
    4. Microsoft.Scripting.dll
    5. Oyster.IntX.dll
    Code (csharp):
    1. Also folders
    2. IronScheme/lib
    3. IronScheme/ironscheme
    So my final structure is
    Code (csharp):
    2. Assets/Plugins/Scheme/[lib|ironscheme]
    3. Assets/Plugins/Scheme/[ironscheme.boot.dll|IronScheme.Closures.dll|IronScheme.dll|Microsoft.Scripting.dll|Oyster.IntX.dll]
    Inside the Unity editor scheme REPL works nice. There are big problems though with the Unity build pipeline and file processing. Specifically:

    1) How I can a new file type to the Project Manager? For example I want to register SchemeScript type and see it included in the context menu Create option.
    2) How I can tell to Unity to process some particular file type (for example .sls) with an external tool like a Scheme compiler or C# custom preprocessor? How I can control when this processing happens: before C# compiler or after?
    3) How I can tell Unity that this file must be re-processed when it has changed?
    4) How I can tell Unity that some files (Scheme libraries, other data files) should be copied to some designated target during the application build?
    5) How I can tell Unity to different file types with specific editors when clicked on?
    6) How add "preview content of file" feature for custom file types when they are selected in the project manager?

    At this point, I have made a few experiments with some simple GUI projects using IronScheme in Unity. These projects run OK in Unity, but fail to run when published as standalone applications.

    P.S. Attachment has a UnityPackage with my project. You can try enter the next sequences in the Scheme console

    For simple Math
    Code (csharp):
    2. > (+ 1 2)
    3. 3
    For function definition
    Code (csharp):
    2. > (define (foo n) (* n n))
    3. #<unspecified>
    4. > (foo 5)
    5. 25
    Just a closure example
    Code (csharp):
    2. > (define (foo n) (lambda (m) (set! n (+ n m)) n))
    3. #<unspecified>
    4. > (define bar (foo 10))
    5. #<unspecified>
    6. > (bar 1)
    7. 11
    8. > (bar 1)
    9. 12
    10. > (bar 19)
    11. 22
    Access to the Unity's Transform and Vector3
    Code (csharp):
    2. > (clr-call Transform Translate (clr-prop-get MonoBehaviour transform 'this) (clr-new Vector3 100 100 100))
    3. #<unspecified>
    Load external script file. Make in the Assets folder
    Code (csharp):
    2. (import (rnrs))
    3. (define (fib n)
    4.   (if (< n 2)
    5.       n
    6.       (+ (fib (- n 2)) (fib (- n 1)))))
    Then inside console
    Code (csharp):
    2. (include "Assets/fib.scm")
    3. (fib 10)

    Attached Files:

    Last edited: Jan 18, 2013