Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Lua is too mainstream

Discussion in 'General Discussion' started by darkhog, Jul 15, 2015.

  1. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    Does anyone know of any runtime Lisp interpreter for Unity3d? I know someone had made such thing but AFAIK it wasn't released. I plan to use it for my game's scripting (as in, for mods - actual game will still use C#). Lua is just too mainstream. Sorry.
     
    EliasMasche likes this.
  2. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,148
  3. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    4,044
    someone really needs to invent hipsterscript.
     
  4. TheCodez

    TheCodez

    Joined:
    Sep 19, 2014
    Posts:
    14
    I wish! I had worked on a lisp interpreter in C++ before and got it to somewhat work (I was constantly plagued by memory leaks I could not solve). Lua is used way to much, and even through it can emulate classes I still want a language with classes and a C++ style syntax. There is the Squirrel scripting language but there is not .Net/Unity3D wrapper as far as I know. Which is awful! I'm sick and tired of Lua everywhere!
     
    EliasMasche likes this.
  5. delinx32

    delinx32

    Joined:
    Apr 20, 2012
    Posts:
    417
    I wrote this a few years ago, it was an exercise in design patterns and new language features (at the time) lambas, etc. It's a customizable C syntax real time language parser. I don't know how its held up over the years, but it was pretty awesome when I wrote it:

    https://ksharp.codeplex.com/

    I just pulled this down and recompiled it out of the XNA environment and it still works. It runs on .net 3.5 so it should work in Unity fine. Here is an example of how you would set up a custom class, pass it to the script and use it:

    Code (CSharp):
    1.         [TestMethod]
    2.         public void TestDoubleFields()
    3.         {
    4.             DoubleFields d = new DoubleFields(10, 10);
    5.             ks.Reset();
    6.             ks["Doub"] = d;
    7.  
    8.             string testString = "int i = Doub.Simp.a;";
    9.             ks.Eval(testString);
    10.             Assert.AreEqual(10, ks["i"]);
    11.  
    12.             testString = "Doub.Simp.a = 17 + 35;";
    13.             ks.Eval(testString);
    14.             Assert.AreEqual(17 + 35, d.Simp.a);
    15.  
    16.             testString = "Doub.Simp.a = Doub.Simp.a + Doub.Simp.b;";
    17.             ks.Eval(testString);
    18.             Assert.AreEqual(17 + 35 + 10, d.Simp.a);
    19.         }
    And doing something more advanced like a for/while loops:
    Code (CSharp):
    1.         [TestMethod]
    2.         public void TestFor()
    3.         {
    4.             // test for with global var
    5.             string testString = "int i = 0;int b = 0;";
    6.             testString += "for(i=0;i<10;i = i+1) { b = b + 2; }";
    7.  
    8.             ks.Eval(testString);
    9.             Assert.AreEqual(10, ks["i"]);
    10.             Assert.AreEqual(20, ks["b"]);
    11.  
    12.             // test for with inline variable declaration
    13.             ks.Reset();
    14.             testString = "int b=0;for(int i=0;i<10;i = i+1) { b = b + i; }";
    15.             int b = 0;
    16.             for (int i = 0; i < 10; i++)
    17.                 b = b + i;
    18.             ks.Eval(testString);
    19.             Assert.AreEqual(10, ks["i"]);
    20.             Assert.AreEqual(b, ks["b"]);
    21.         }
    22.  
    23.         [TestMethod]
    24.         public void TestWhile()
    25.         {
    26.             string testString = "int i = 0;while(i<10) i = i + 1;";
    27.             ks.Reset();
    28.             ks.Eval(testString);
    29.             Assert.AreEqual(10, ks["i"]);
    30.  
    31.             testString = "int i = 0;while(i<10) { i = i + 1; }";
    32.             ks.Reset();
    33.             ks.Eval(testString);
    34.             Assert.AreEqual(10, ks["i"]);
    35.  
    36.  
    37.         }
     
    Last edited: Jul 16, 2015
    EliasMasche and TylerPerry like this.
  6. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    Yeah, I know about it. But I was hoping for something more integrated with Unity, so I can make it e.g. call c# functions from lisp (by "binding" certain s-expressions to things like "move that object" or "change color of this object").
     
  7. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    Sorry, but I'm looking for Common Lisp or as close to it as possible. If I'd want C-like syntax, I'd just use .NET Compiler class (or whatever it is called) that let you compile stuff on the run.
     
  8. schmosef

    schmosef

    Joined:
    Mar 6, 2012
    Posts:
    851
    I'm waiting for ArnoldC to be ported to Unity. :D
     
    calmcarrots and Deleted User like this.
  9. Deleted User

    Deleted User

    Guest

    Here you go... :D

    Code (CSharp):
    1. Using someone.elses.ideas
    2.  
    3. Private fool getoutofbed ;
    4. Private fool  tighttrousers;
    5. Private fool conformist;
    6.  
    7. Public VoidOfSoul (Tight){
    8.  
    9. If (getoutofbed == true) {
    10.  
    11. Wear.tight.trousers = fool (true);
    12.  
    13. else if(tighttrousers == true){
    14.  
    15. Transform.Go.Outside = offeropinion(thatnobodycaresabout(0,0,0));
    16.  
    17. }
    18.  
    19. Public VoidOfSoul (conform){
    20.  
    21. Do {
    22.  
    23. Pretend.not.to.conform } While (conformist == true);
    24.  
    25. ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] Lots.of.brackets TO (show.not.conforming);
    26.  
    27. ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
    28.  
    29.  
    30.  
     
  10. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    It doesn't work on IOS and IIRC it doesn't work on IL2CPP.
     
  11. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
  12. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    2,363
    Could write your own lisp parser/interpreter?
    That's the beauty of lisp. The syntax is so simple.
     
  13. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    Do you think, if I'd be able to do so myself, this thread would exist? Or rather I'd start cranking and once done push to the asset store? Again, I'd like to ask @hww for sharing his interpreter code.
     
  14. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    This is kind of off topic, but I still would like to ask.
    What is the reason that the title of this thread doesn't mention that you are looking for Lisp interpreter? You are not looking for anything that is related to Lua, so why do you even bother to mention it? There is no reason to mention it and especially no reason to mention it in the title.
     
  15. NoPiece

    NoPiece

    Joined:
    Jan 5, 2014
    Posts:
    26
  16. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Damn Hipsters. :)
     
  17. Dreamaster

    Dreamaster

    Joined:
    Aug 4, 2014
    Posts:
    148
    This post just made my entire day a lot brighter...
    QFT:

     
    Deleted User likes this.