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. Dismiss Notice

Lua in Unity?

Discussion in 'Scripting' started by tookydo, Jul 15, 2014.

  1. tookydo

    tookydo

    Joined:
    Jul 15, 2014
    Posts:
    75
    Is there a way to add lua into unity. Not for modding or anything. I want to be able to use it just like C# Javascript or Unity Script. Is this possible. If so please let me know where to find it. It would be a huge help. Money isnt a question either I dont care how much it would cost lol.
     
  2. DexRobinson

    DexRobinson

    Joined:
    Jul 26, 2011
    Posts:
    594
  3. tookydo

    tookydo

    Joined:
    Jul 15, 2014
    Posts:
    75
  4. DexRobinson

    DexRobinson

    Joined:
    Jul 26, 2011
    Posts:
    594
    I don't really know, not too familiar with Lua. I think you can use the whole api but don't quote me on it.
     
  5. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,523
    It's not practical. All the Lua implementations that I'm aware of are runtime interpreters. They don't compile into native Unity or .NET DLLs. To use them "like" C#/UnityScript, you'd have to write a wrapper that hands control to Lua when the game starts. It would also need to handle Unity messages such as Start(), Update(), OnTriggerEnter(), etc., and send them to Lua.

    If you don't want to use Anomalous Underdog's Luainterface wrapper (which requires Unity Pro), you can use George Foot's excellent KopiLuaInterface. Danny Goodayle wrote a short tutorial on how to set it up. You can also use NLua, which uses the fast C DLL bind when available but can use KopiLua for compatibility with Unity free.

    All three implementations are based on Luainterface, which allows you to register C# functions with the Lua environment. You can register individual UnityEngine methods such as Debug.Log(), but again it's highly impractical unless you only need a few. There are other issues, too, such as working with other scripts in UnityScript and C#.

    So, in short, Lua can work well as a runtime interpreter (e.g., for user scripting), but isn't practical for core Unity development -- unless you write your own Lua to .NET DLL compiler, or a translator to C#, or something like that.