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

Jobs and Lua or any other scripting language

Discussion in 'Entity Component System' started by benzy54n, Jan 28, 2021.

  1. benzy54n

    benzy54n

    Joined:
    Dec 21, 2013
    Posts:
    34
    I would like to add some modding to my game. I use Jobs extensively and would like the modding to touch some of the code in the Jobs. This of course causes issues and constraints. For instance my first attempt was to use Moonsharp a LUA interpreter for Unity. A few issues was that everything in the interpreter is a class and not structs with basic types. I was able to somewhat get around that using some static functions which isn't ideal. However, after I did some code gymnastics to get this it turns out that Moonsharp doesn't work across threads from a single script. I would need to load the script every for every thread instance which isn't ideal. There are some other things I need to explore with the Moonsharp solution but I still don't want to loose the speed benefits of the job system so i might be coming to what is more worth it in the end. Also I am not married to LUA was just the first thing I tried.

    So a question is has anyone got external scripting working with Jobs? The way I would envision the best solution for me is to load all the external scripts with the functions and have them "compiled" and then pass them to the jobs as function pointers via delegates. I have used function pointers and delegates in my jobs prior so i know that's possible.

    Any thoughts would be appreciated.
    Thanks,
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,580
    I was working with moonsharp before.While I like it in general, but I had same issue with lua multithreading.
    I gave up on that, and I wrote instead own parser, which is very close to javascript alike and I do call own custom functions, to "communicate" correctly with jobs.

    I convert parsed code into int representation of instructions and values. Kind of like assembly approach.
    This way I can even use it with burst.

    You could also give a shot to miniscript
    https://forum.unity.com/threads/miniscript-lightweight-scripting-language-for-your-game.373853/
    I don't know, if it will suffice your requirements.
     
  3. Imakhiil

    Imakhiil

    Joined:
    Oct 11, 2013
    Posts:
    96
    If you're going to play with function pointers, you may as well look at LuaJIT and treat it as any other unmanaged library.
     
  4. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    944
    There's an asset in the asset store that allows C# for runtime scripting. Not sure if it can have access to DOTS libraries or be able to work in job threads.
     
  5. Rytif

    Rytif

    Joined:
    Dec 28, 2012
    Posts:
    7
    That isn't runtime scripting. It recreates multiple domains in .NET and crashes your app.