Search Unity

Lua Framework [Confirmed: works in iOS!]

Discussion in 'Assets and Asset Store' started by georgesdimitrov, Feb 23, 2015.

  1. georgesdimitrov

    georgesdimitrov

    Joined:
    Feb 4, 2013
    Posts:
    50
    Hello everyone,

    I've just released a script asset, which is an add-on for MoonSharp, a brand new Lua - Unity/C# bridging library developed by a friend of mine. It allows reading Lua data into Unity in a way that's faster, easier and more intuitive than anything previously available, and works on both Unity and Unity Pro!

    If you've ever wanted to use Lua to help build your game or add modding elements, it's now easier than ever. I'm using this asset myself in a game under development, a Legend Of Grimrock kind-of oldschool RPG, which uses Lua for asset definitions and modding the same way LoG does.

    Asset Store Link: https://www.assetstore.unity3d.com/#!/content/30055


    Description :

    Lua Framework
    allows you to easily and automatically convert data defined in the Lua script language to .NET objects, and vice-versa. It works like XML or JSON readers, but instead of a markup language, you now have access to a powerful programming language to define your game or application’s logic. Like many top-selling games did, choosing Lua can greatly streamline the game design process and most importantly, allow easy-to-implement modding capacities.

    Lua Framework is built on the power of MoonSharp, a modern and free .NET implementation of the Lua language. As opposed to previous .NET to Lua bridges such as LuaInterface, NLua or UniLua, MoonSharp provides a very intuitive user experience with fast learning curve, fast performance, is regularly updated, supports latest Lua 5.2, and supports Unity’s Mono implementation of the .NET language out of the box, on all Unity versions and licenses, including iOS. You can learn more about MoonSharp and download it at moonsharp.org.

    For now, the Lua Framework has two main modules: LuaReader and LuaWriter. LuaReader automatically maps Lua variables and tables to .NET objects. LuaWriter creates a Lua script representation of .NET objects. Currently supported types are:

    - Built-in types: bool, int, float, double, string, byte & decimal;
    - Enums;
    - Unity-specific structs: Color, Color32, Rect, Vector2, Vector3 & Vector4;
    - Lua functions (closures)
    - ANY custom classes with public properties;
    - One-dimensional or two-dimensional arrays of any supported type;
    - Generic Lists or Dictionaries of any supported type;
    - Any possible nesting, for example List<Dictionary<string, Vector3[]>>.

    The code for the Lua Framework is clean and professional, performance-optimized, with full intellisense support.

    Manual:


    You can download the complete manual to get a better understanding of how this asset works:
    Lua Framework Manual V 1.0.pdf.

    Example:

    But as a quick example of what this can do, Lua Framework can map the following Lua code:

    defineEnemy{
    name = “Bandit”,
    health = 50,
    attackPower = 3.5,
    }

    defineEnemy{

    name = “Bandit Leader”,
    health = 125,
    attackPower = 5,
    }
    To this C# class:
    public class Enemy
    {
    public string name { get; set;}
    public int health { get; set;}
    public float attackPower { get; set;}
    }

    With one simple function call (called by the Lua defineEnemy function, see manual for details):

    Enemy enemy = LuaReader.Read<Enemy>(luaTable);

    Without the need of any further attributes, casting or manual parsing and reading of lua tables/data. The equivalent code with NLua would be:

    Enemy enemy = new Enemy();
    enemy.name = (string) luaTable[name];
    enemy.health = (int) (double) luaTable[health];
    enemy.attackPower = (float) (double) luaTable[attackPower];
    Which is longer of course as Lua Framework takes care of all the castings, but also less flexible: if you decide to change your Enemy class in the future, by adding, renaming or removing properties, you need to change the parsing code. Also, the above will raise errors if your lua table happens to miss a property, requiring you to add a lot more code if you want some properties to be optional, or safety against user scripts for mods.

    -----------------------------------

    Questions, comments, feature requests? Don't hesitate to post, I'll be glad to answer and incorporate anything you need in future updates.
     
    Last edited: Sep 3, 2015
    EliasMasche likes this.
  2. Fubeca

    Fubeca

    Joined:
    Jul 21, 2013
    Posts:
    41
    Does this happen to work on iOS?
     
  3. georgesdimitrov

    georgesdimitrov

    Joined:
    Feb 4, 2013
    Posts:
    50
  4. Fubeca

    Fubeca

    Joined:
    Jul 21, 2013
    Posts:
    41
    I looked closer at your sample above and I see that you're doing manual initialization and binding of the lua to project objects. That should work fine. At first glance I thought it was using reflection to do dynamic binding, and that doesn't work on iOS.

    I'll have to give it a try. :)
     
  5. georgesdimitrov

    georgesdimitrov

    Joined:
    Feb 4, 2013
    Posts:
    50
    My asset DOES use Reflection to dynamically map Lua data to project objects by enumerating through their properties, but it does so on types known ahead at compile-time, without generating any code at runtime with Reflection.Emit. According to my research (here: http://jonathanwagner.com/blog/2013...to-mono-runtime-limitations-for-unity-on-ios/ and here: http://developer.xamarin.com/guides/ios/advanced_topics/limitations/) this IS supported just fine on iOS.

    Just to make it clear, this "auto-binding" is one of the main points of this asset. If you wish, you can download MoonSharp for free and use it like this:

    Enemy enemy = new Enemy();
    enemy.name = luaTable["name"];
    enemy.health = (int) luaTable["health"];
    enemy.attackPower = (float) luaTable["attackPower"];

    But my framework allows you to simplify it to (Enemy type is specified at compile-time):

    Enemy enemy = LuaReader.Read<Enemy>(luaTable);

    Where it enumerates on Enemy's properties, looks if the table contains them, and makes the necessary casts. It also works recursively, so if your Enemy had a property like

    Attack attack { get; set; }

    which is it's own class, it would work just fine and map any sub- or sub-sub-classes in whatever structure you have.

    Also, by support of Unity structs, you can do:

    Standard MoonSharp:

    Vector3 vec3 = new Vector3((float) luaTable[1], (float) luaTable[2], (float) luaTable[3]);

    MoonSharp + LuaFramework:

    Vector3 vec3 = LuaReader.Read<Vector3>(luaTable);

    With the avantage that it handles situations like if for example your lua table only contained 2 values instead of 3, and it auto-handles it if you have custom classes which have Vector3 (or other supported Unity Types) properties.

    And then there's the LuaWriter counterpart which allows you to serialize objects to Lua scripts, you can check the manual for examples.

    Hope this makes it clearer!
     
  6. Fubeca

    Fubeca

    Joined:
    Jul 21, 2013
    Posts:
    41
    Very nice, and very useful. And exactly how binding to Lua should work. :) I haven't used a managed lua system yet, but last time I messed with Lua it was pretty messy to get it all hooked up. I'd love to clean that up. I was dreading doing manual binding to a non-managed Lua for an upcoming game, so this asset is very timely.

    It's been a while since I tried to use reflection on iOS in Xamarin, and I don't recall what I was trying to accomplish with it. I do remember that it took several hours to figure out another way to accomplish the same thing and rewrite the code to work that other way instead of the original few lines that just used reflection. It was in the very early days of Xamarin, though, so maybe whatever it was that I tried to do before would work now. I haven't *ever* done anything directly with the DLR and Emit, so I know it wasn't that. :) In non-iOS stuff, I use a lot of reflection to get attributes and do stuff with some DAL classes I've built, so it was probably related to that.

    Sounds like your asset is something I'll want to snag for the regular non-game stuff I do, too. :)
     
  7. georgesdimitrov

    georgesdimitrov

    Joined:
    Feb 4, 2013
    Posts:
    50
    Hey, just as a quick update, I got in touch with the MoonSharp developper, and he says that while the MoonSharp code "should" work fine on iOS, users have reported problems due to ANTLR, the .dll MoonSharp uses for parsing lua scripts. He says he will see if he can get an iOS device to test things out.
     
  8. Spacemarine658

    Spacemarine658

    Joined:
    Dec 9, 2012
    Posts:
    14
    Does this work with unity 5.0?
     
  9. georgesdimitrov

    georgesdimitrov

    Joined:
    Feb 4, 2013
    Posts:
    50
    Hi,

    Absolutely, I just tested it and it works great with Unity 5. The MoonSharp developper has also managed to remove the need for the ANTRL .dll... I tested a beta build which now makes MoonSharp work way faster and could actually make it work on iOS! Crossing fingers...
     
  10. Xanathar

    Xanathar

    Joined:
    Sep 30, 2014
    Posts:
    6
    Jumping in.. another friend of mine/us will hopefully be testing the new MoonSharp build on iOS in the weekend. It already works wonderfully under Linux with mono --full-aot which should be equivalent of what Unity does for iOS but I need more testing ;)
     
  11. Xanathar

    Xanathar

    Joined:
    Sep 30, 2014
    Posts:
    6
    I can confirm :

    MoonSharp 0.9.0 runs on iOS !
     
  12. georgesdimitrov

    georgesdimitrov

    Joined:
    Feb 4, 2013
    Posts:
    50
    Hi everyone,

    I've just released a small update to the Lua Framework, it adds support for reading Lua functions (closures) to the C# side, and for adding custom readers.

    Custom readers allow you to format your Lua data in any way you like, and also provides support for custom structs. For example, standard Lua Framework behavior reads this lua:

    person = {
    name = “John”,
    age = 26,
    }
    Into this C# class:

    public class Person
    {

    public string name { get; set; }
    public int age { get; set; }
    }


    But you could also define a custom reader like this (C#):

    LuaReader.AddCustomReader(typeof(Person), dynValue =>
    {
    var luaTable = dynValue.Table;
    return new Person{

    name = LuaReader.Read<string>(luaTable.Get(1)),
    age = LuaReader.Read<int>(luaTable.Get(2))
    };
    });


    And then format your Lua tables like this:

    person = {“John”, 26}
    person2 = {“Maria”, 31}
    person3 = {“Paul”, 17}


    For more details, see the updated manual.

    Asset Store link: https://www.assetstore.unity3d.com/en/#!/content/30055
    Manual v1.1: http://www.georgesdimitrov.com/wp-content/uploads/Lua-Framework-Manual-V1.1.pdf
     
    Last edited: Sep 3, 2015
  13. Tsetso

    Tsetso

    Joined:
    Aug 21, 2014
    Posts:
    2
    I'm thinking about "smart" config file that looks like:

    version ="1.0.19"
    health =10
    attackPower =1

    --Read User from C#
    if User.level > 20 then Ads.enabled =false end


    I'm confused if Apple would approve such use. It is specified that only JavascriptCore is allowed etc etc but we see things like codea.io. That makes me wander can se use moonsharp based thing when making production apps? Any thoughts on that?

    I'm especially interested in where is the line between code and data...
     
  14. georgesdimitrov

    georgesdimitrov

    Joined:
    Feb 4, 2013
    Posts:
    50
    Hi,

    There shouldn't be any problem doing what you want to do above. The easiest thing would be to put your .lua code as a text file in a Resources folder and load/execute it at runtime, but there's also the streaming assets option: http://docs.unity3d.com/Manual/StreamingAssets.html.

    You should read on how moonsharp passes C# objects to Lua here: http://www.moonsharp.org/objects.html.

    For your purposes, just the first example, titled "Keep it simple" is ample enough:

    1. Tag your User and Ads classes with a [MoonSharpUserData] attribute
    2. Call UserData.RegisterAssembly(); somewhere once to initialize the C#-Lua link for classes marked UserData
    3. Create a new Script object, like var lua = new Script();
    4. Register your objects in the lua Script:
    lua.Globals["User"] = user; <- where user is a reference to your user.
    lua.Globals["Ads"] = ads; <- where ads is a reference to your ads.​
    5. Get the text for your script, for example var configScript = Resources.Load<TextAsset>("config.lua").text; <-- Actual file is named config.lua.txt in the resources folder because Unity wants .txt files.
    6. Run the script: lua.DoString(configScript);

     
  15. georgesdimitrov

    georgesdimitrov

    Joined:
    Feb 4, 2013
    Posts:
    50
    Hi guys,

    Just a quick update on the iOS status.

    I got an iPad last week and managed today to build and run the demo scene of Lua Framework on my iOS device.

    Conclusion: Lua Framework works 100% perfectly on an iPad Air 2 with iOS 9 installed. :)
     
  16. Tsetso

    Tsetso

    Joined:
    Aug 21, 2014
    Posts:
    2
    Hi George,

    Thanks for the post. I had no problem integrating Lua and exposing our custom data. Good to hear the compatibility with iOS9.
     
  17. georgesdimitrov

    georgesdimitrov

    Joined:
    Feb 4, 2013
    Posts:
    50
    Happy to hear that! If you're using the asset and are happy with it, consider submitting a review to the store, it always helps future users... :)
     
  18. JustinAHS

    JustinAHS

    Joined:
    Feb 18, 2013
    Posts:
    33
    Hey, does this asset support all the intricacies of regular Lua coroutines? How nicely does it play with Unity's coroutines and C# code?
    How difficult would it be for me to do something like this:
    Code (Lua):
    1.  
    2. co = coroutine.create(function (i)
    3.     local a = coroutine.yield(i);
    4.     local b = coroutine.yield(i, a);
    5.     local c = coroutine.yield(i, a, b);
    6.     return i, a, b, c;
    7. end);
    8.  
    Code (CSharp):
    1.  
    2. IEnumerator CallLua () {
    3.     //Somehow call coroutine.resume(co, 0);
    4.     //Somehow get all the results of the call: 0
    5.     yield return null;
    6.     //Somehow call coroutine.resume(co, 1);
    7.     //Somehow get all the results of the call: 0, 1
    8.     yield return null;
    9.     //Somehow call coroutine.resume(co, 2);
    10.     //Somehow get all the results of the call: 0, 1, 2
    11.     yield return null;
    12.     //etc.
    13. }
    14. void Start () {
    15.     StartCoroutine(CallLua());
    16. }
    17.  
     
    hakankaraduman likes this.
  19. georgesdimitrov

    georgesdimitrov

    Joined:
    Feb 4, 2013
    Posts:
    50
    Hi!

    Moonsharp supports coroutines entierly, and even handles them even better than stock Lua: http://www.moonsharp.org/coroutines.html

    As I personnaly haven't played much with coroutines on the Lua side, I haven't implemented specific support for coroutines in Lua Framework beyond what Moonsharp already allows you to do. But this means you should probably be able to use Moonsharp's built-in coroutine support to do what you wish above, while still using the Lua Framework auto type-mapping capabilities.

    I will do some tests in the coming days to see how Lua coroutines work with Unity coroutines, and see if there is something I could provide in my framework to automate the process of creating and handling these.
     
  20. PKrawczynski88

    PKrawczynski88

    Joined:
    Nov 14, 2013
    Posts:
    15
    I'm kinda stuck for couple of hours already figuring best way to serialize Table object. Just letting you know it would be great to have something that could handle it automatically.

    It would be awesome if there was easy way to serialize table object that can contain nested table objects (be it dictionary or list). WriteLine function sadly writes everything as a string, and I cant WriteObject because I use Tables and not custom objects that use built in types. Explanation why I do things such a way are below:

    I have custom component classes (non mono behaviours) that take only Table object into constructor. Lua scripts define my game entity components in tables and create them in c# with simple add method that takes table as argument. Scripts that contain game logic which I want to be moddable use entity references to access variables from tables in components. Its all working pretty well and i'm happy with end result. I'm creating turn based game so execution speed while important has lower priority than game modding capabilities.

    @georgesdimitrov do you have any suggestions or maybe you could consider supporting serializing table as this asset is amazing what it does - except this edge case. I could of course not think about something that may be obvious to you as I'm still learning my ways around c# (I have years of experience in other tech - languages closer to lua than c# though), so maybe afterall writing tables containing all those DynValue objects back as lua objects is piece of cake and I just cant figure it out :)
     
  21. georgesdimitrov

    georgesdimitrov

    Joined:
    Feb 4, 2013
    Posts:
    50
    Hi,

    For this you need an Lua serializer. I didn't include one myself as there are many available out there based on your needs (do you need to serialize closures or not, does it have to be readable...). There's a quite comprehensive list here : http://lua-users.org/wiki/TableSerialization.

    I've tried a few and for my own game I currently use the [prtr-dump] one. I load the code in my lua Script state and call it from there. Basically it's Lua serializing Lua. I guess there's maybe a C# serializing Lua code somewhere out there, or I could try to port that one to C# when I get time.
     
  22. PKrawczynski88

    PKrawczynski88

    Joined:
    Nov 14, 2013
    Posts:
    15
    @georgesdimitrov
    Thanks for links, thats enlightening. Since I pull and modify my values in c# from Table object and it isnt serializable I guess I will have to figure something out on my own in the end. I only use lua to process logic and define variables but not to keep entities in it.

    Either way serializing c# Table object would be great addition for people with use edge case as mine.

    I will go and leave positive review since I feel fairly happy with my purchase :)
     
  23. georgesdimitrov

    georgesdimitrov

    Joined:
    Feb 4, 2013
    Posts:
    50
    Hmmm, what type of serialization would you like? To output the table to an Lua script you could run back in? If the data in your Tables is easily convertible to C# and back (numbers, strings and tables of those) it's easy to implement. If it can contain functions it's much more complicated.
     
  24. PKrawczynski88

    PKrawczynski88

    Joined:
    Nov 14, 2013
    Posts:
    15
    Yeah I just implemented that yesterday :) Just had to give it some thought and dig into how everything works - which I had to do anyway at some point. Thanks for links though, they might come in usefull in future.
     
  25. Bowie-Xu

    Bowie-Xu

    Joined:
    Sep 14, 2011
    Posts:
    28
    Hi
    Does it support WebGL platform??
    I use Unity 5.3.0f4.
    Thanks!
     
  26. dogfacedesign

    dogfacedesign

    Joined:
    Jan 10, 2016
    Posts:
    70
    Pretty excited about using this package - thanks for publishing it! Running into a slight issue though. When I do this:

    lua.Globals["defineResource"] = (Action<DynValue>) DefineResource;

    I am getting this error .... any ideas?

    error CS0246: The type or namespace name `Action`1' could not be found. Are you missing a using directive or an assembly reference?

    Thanks in advance!
     
  27. dogfacedesign

    dogfacedesign

    Joined:
    Jan 10, 2016
    Posts:
    70
    Whoops, never mind ... was missing "using System;" in my script :D
     
  28. dogfacedesign

    dogfacedesign

    Joined:
    Jan 10, 2016
    Posts:
    70
    Man, I am pulling my hair out over here a wee bit :)

    I am trying to read in and parse this pretty simple LUA variable into a "string[] monthNames" in one of my Unity scripts:

    monthNames = {
    "January",
    "February",
    "March",
    "April",
    "May",
    "June",
    "July",
    "August",
    "September",
    "October",
    "November",
    "December"
    }

    But I keep running into all sorts of casting issues trying to go from DynValue to strings. Am I missing some obvious approach here? Sorry, I'm still learning C# and Lua! Any advice would be very much appreciated!
     
  29. dogfacedesign

    dogfacedesign

    Joined:
    Jan 10, 2016
    Posts:
    70
    As a followup to the above post, I managed to get it working this way:

    Code (csharp):
    1.  
    2. DynValue tmp = lua.Globals.Get ("monthNames");
    3. var luaTable = tmp.Table;
    4. IEnumerable<DynValue> tmp2 = luaTable.Values;
    5.  
    6. foreach(var m in tmp2)
    7. {
    8.     Debug.Log(m.String);
    9. }
    10.  
    Is there a better way to do this, or did I actually do it the preferred way? heheh.

    Now I am running into issues trying to parse it in this format, where I have the # of days in each month associated with each month name.

    Code (csharp):
    1.  
    2. monthNames = {
    3.     { "January", 30 },
    4.     { "February", 18 ),
    5.     { "March", 31 },
    6.     { "April", 30 },
    7.     { "May", 31 },
    8.     { "June", 30 },
    9.     { "July", 31 },
    10.     { "August", 31 },
    11.     { "September", 30 },
    12.     { "October", 31 },
    13.     { "November", 30 },
    14.     { "December", 31 },
    15. }
    16.  
    Any suggestions? Thanks in advance!

    Cheers.
     
  30. StudioEvil

    StudioEvil

    Joined:
    Aug 28, 2013
    Posts:
    66
    Hi @georgesdimitrov,
    we are searching for a lua implementation that is aot friendly. We use UniLua (full c# implementation) but we have many issues on Xbox One. Do you know if your implementation works fine on Xbox One?
     
  31. dogfacedesign

    dogfacedesign

    Joined:
    Jan 10, 2016
    Posts:
    70
    I have an interesting scenario that I could use a little guidance on. I am trying to "genericize" my config file reader. So instead of constantly adding in statements to process a new directive, I just want it to process each assignment in my LUA script (either it is a scalar, string, table, etc), and have it assign it to a new array member in a config variable. Does that make sense? Looks like right now, I have to explicitly code for each one. Any ideas out there?
     
  32. Elenesski

    Elenesski

    Joined:
    May 19, 2013
    Posts:
    22
    I would like to know if something a little bit more complicated is possible with the framework, namely:

    Code (csharp):
    1.  
    2.   public class Armor {
    3.      public string Name;
    4.      public string Type;
    5.      public float Durability;
    6.      public float Protection;
    7.    }
    8.  
    9.    public class Enemy {
    10.      public string name { get; set;}
    11.      public int health { get; set;}
    12.      public float attackPower { get; set;}
    13.      public List<Armor> Armors { get; set; }
    14.    }
    15.  
    Where Enemy contains a list of Armor. Can LUA specify this in some way?

    The code documentation implies I could say:

    Code (csharp):
    1.  
    2.    defineEnemy {
    3.      name = "name",
    4.      health = 5,
    5.      attackPower = 4.4,
    6.      { { Name = "Metal Helmet", Type="Head", Durability=15 },
    7.       { Name = "Breast Plate", Type="Chest", Durability=50 } }
    8.    }
    9.  
    Is this correct/possible?
     
  33. georgesdimitrov

    georgesdimitrov

    Joined:
    Feb 4, 2013
    Posts:
    50
    Of course, this works perfectly. You just forgot the Armors = part in : Armors = { { Name = "Metal Helmet"...

    The whole point of this framework (as opposed to just downloading Moonsharp for free) is that it reads automatically all tables and puts them into lists/dictionaries/arrays/whatever.

    It can get as complicated as you like, for example, here's a definition for an axe from my own game (I use a component model):

    Code (CSharp):
    1. defineObject{
    2.     name = "ironAxe",
    3.     baseObject = "base_item",
    4.     components = {
    5.         model = {
    6.             prefab = "ironAxe",
    7.         },
    8.         collider = {
    9.             physicsType = "dynamic",
    10.             colliderType = "box",
    11.             offset = {0, 0, 0},
    12.             size = {0.4, 0.1, 1.4},
    13.         },
    14.         item = {
    15.             uiName = {
    16.                 en = {
    17.                     singular = "Iron Axe",
    18.                     plural = "Iron axes",
    19.                     startsWithVowel = true,
    20.                 },
    21.                 fr = {
    22.                     singular = "Hâche de fer",
    23.                     plural = "Hâches de fer",
    24.                     gender = 1,
    25.                 },
    26.             },
    27.             icon = "ironAxe",
    28.             equipmentType = "rightHand",
    29.             material = "iron",
    30.             weight = 2.0,
    31.             baseValue = 90,
    32.             uiDescription = {
    33.                 en = "A common iron axe, inexpensive to make: this weapon hits heavily, but without much grace.",
    34.                 fr = "Une hâche de fer ordinaire, qui ne coûte pas grand chose à fabriquer: cette arme peut frapper fort, mais sans grande grâce.",
    35.             },
    36.             collisionSound = "SFX_SwordImpact";
    37.         },
    38.         weapon = {
    39.             skill = "axes",
    40.             damage = {9, 14},
    41.             accuracy = 0,
    42.             cooldown = 5,
    43.             attackSound = "axe_swing",
    44.         },
    45.     },
    46. }
     
  34. Elenesski

    Elenesski

    Joined:
    May 19, 2013
    Posts:
    22
    Awesome, thanks.
     
  35. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,532
    Man this looks so juicy. Really want to check it out soon.
     
  36. exltus

    exltus

    Joined:
    Oct 10, 2015
    Posts:
    58
    Is there any way how can I use c# property in lua code?
    For example : I have list of integers in my singleton class and I want lua method, that will return true if this list contains some number. Is it possible?
     
  37. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    Very interesting asset.
    How would a simple lua code look like to create a game object and make it spin.
     
  38. georgesdimitrov

    georgesdimitrov

    Joined:
    Feb 4, 2013
    Posts:
    50
    Hello! I am on a family vacation until August 1st, I will be able to answer the questions in detail once I get back.

    @exltus, I really apologize, I somehow missed the notification that you posted here, or else I would have answered way sooner. Of course it's possible, but I'm not sure exactly what you intend to do. If you expose your C# singleton object to lua, then you can access any of it's properties from lua. It would probably be easier (and faster, less conversions) though to do the "search" method in C# and then expose that method to lua, rather than coding the search function in lua. But any way works.

    @rocki, you cannot directly access unity calls in Lua, as you need a C# class that is a MonoBehaviour to create gameobjects. However, you can make a singleton class that you would call GameObjectManager for example, and in it write C# methods such as CreateObject(some parameters...) and SpinObject(some parameters). Then if you expose the GamObjectManager to lua, for example in c#: script.Globals["goManager"] = gameObjectManager; in lua you will be able to simply call goManager.CreateObject(some parameters...). Does that make sense?
     
  39. taiku

    taiku

    Joined:
    Aug 26, 2013
    Posts:
    8
    What is the reason you don't distribute MoonSharp with the asset?

    What are the exact steps to get MoonSharp in my project? I seem to be an idiot :) if I add the whole .zip release it won;t compile because of the JS files. If I just add the repl and interpreter I still get an error.
     
  40. georgesdimitrov

    georgesdimitrov

    Joined:
    Feb 4, 2013
    Posts:
    50
    Hi taiku,

    I'm not distributing MoonSharp together with Lua Framework because, first of all, it's not my software and I find it more fair to direct users to the original creator's web site. And then, the author of MoonSharp is updating it very regularly with imrpovements and bugfixes, I would need to repackage my asset every time to keep it up to date - it's better to just direct people to the main site, that way you're sure to alway have the latest version.

    As for installation, the only file you really need to put somewhere in your Assets folder is "MoonSharp.Interpreter.dll" in the repl folder. That's it. I just tested it here in Unity 5.4 with the latest MoonSharp (1.6) and it works perfectly without errors.
     
  41. Fariel

    Fariel

    Joined:
    Feb 9, 2013
    Posts:
    29
    Does this asset work with Moonscript 2.0?
     
  42. georgesdimitrov

    georgesdimitrov

    Joined:
    Feb 4, 2013
    Posts:
    50
    Hi Fariel,

    I wouldn't think so, because my asset is essentially and add-on for Moonsharp, which is itself already a Lua interpreter - it seems to be playing the same role as Moonscript. If you wish to be sure, you should ask over at moonsharp.org if there is any compatibility between Moonsharp and Moonscript.
     
  43. Fariel

    Fariel

    Joined:
    Feb 9, 2013
    Posts:
    29
    Once again, I did a dumb. I meant to ask if this works with Moonsharp 2.0. It recently updated from 1.6 to 2.0 and I haven't seen any news from you on supporting it.

    I have no idea what Moonscript is. Sorry!

    (Apparently my phone autocorrects moonsharp to Moonscript)
     
  44. georgesdimitrov

    georgesdimitrov

    Joined:
    Feb 4, 2013
    Posts:
    50
    Hahaha no problem. I had never heard about Moonscript either. I hadn't seen that Moonsharp has gone to version 2 two weeks ago, from what I see from the changes at a glance, it shouldn't break anything, but I'll download the new version and test, and update my asset if there's anything to be fixed.
     
  45. jjsonick

    jjsonick

    Joined:
    Sep 11, 2013
    Posts:
    18
    Hi, for me in Unity 5.4.0f3 LuaFrameworkDemo throws a bunch of errors - I tried with Moonsharp 2.0 and then 1.8. For each, I copied the contents of moonsharp's interpreter/net35 folder (one dll, one xml file and one pdb file) into my project's Assets folder (the moonsharp readme says to use the net35 interpreter files for Unity). When I do so, the console gives these errors (and 1 warning):

    Assets/LuaFramework/LuaWriter.cs(146,34): warning CS0219: The variable `array' is assigned but its value is never used

    Assets/LuaFramework/Tests/LuaFrameworkDemo.cs(26,29): error CS1061: Type `Script' does not contain a definition for `Globals' and no extension method `Globals' of type `Script' could be found (are you missing a using directive or an assembly reference?)

    Assets/LuaFramework/Tests/LuaFrameworkDemo.cs(27,29): error CS1061: Type `Script' does not contain a definition for `Globals' and no extension method `Globals' of type `Script' could be found (are you missing a using directive or an assembly reference?)

    Assets/LuaFramework/Tests/LuaFrameworkDemo.cs(28,29): error CS1061: Type `Script' does not contain a definition for `Globals' and no extension method `Globals' of type `Script' could be found (are you missing a using directive or an assembly reference?)

    Assets/LuaFramework/Tests/LuaFrameworkDemo.cs(35,29): error CS1061: Type `Script' does not contain a definition for `DoString' and no extension method `DoString' of type `Script' could be found (are you missing a using directive or an assembly reference?)

    Assets/LuaFramework/Tests/LuaFrameworkDemo.cs(61,29): error CS1061: Type `Script' does not contain a definition for `DoString' and no extension method `DoString' of type `Script' could be found (are you missing a using directive or an assembly reference?)

    Assets/LuaFramework/Tests/LuaFrameworkDemo.cs(79,25): error CS1061: Type `Script' does not contain a definition for `DoString' and no extension method `DoString' of type `Script' could be found (are you missing a using directive or an assembly reference?)

    Assets/LuaFramework/Tests/LuaFrameworkDemo.cs(80,61): error CS1061: Type `Script' does not contain a definition for `Globals' and no extension method `Globals' of type `Script' could be found (are you missing a using directive or an assembly reference?)

    Assets/LuaFramework/Tests/LuaFrameworkDemo.cs(80,44): error CS1502: The best overloaded method match for `LuaFramework.LuaReader.Read<LuaFramework.Tests.Attack>(MoonSharp.Interpreter.DynValue)' has some invalid arguments

    Assets/LuaFramework/Tests/LuaFrameworkDemo.cs(80,44): error CS1503: Argument `#1' cannot convert `object' expression to type `MoonSharp.Interpreter.DynValue'

    Assets/LuaFramework/Tests/LuaFrameworkDemo.cs(81,148): error CS1928: Type `object' does not contain a member `Debug' and the best extension method overload `LuaFramework.Tests.TestsDebug.Debug(this LuaFramework.Tests.BuiltInTypesObject)' has some invalid arguments

    Assets/LuaFramework/Tests/LuaFrameworkDemo.cs(81,148): error CS1929: Extension method instance type `object' cannot be converted to `LuaFramework.Tests.BuiltInTypesObject'
     
  46. georgesdimitrov

    georgesdimitrov

    Joined:
    Feb 4, 2013
    Posts:
    50
    Hi,

    I don't know why you are getting those errors. I finally made some tests with Moonsharp 2.0, and everything works perfectly fine on my end, on Unity 5.4.1f. You should maybe make sure that you have a clean install of Moonsharp? I removed the old dll file, and instead installed the entire new "unitypackage" provided with Moonsharp 2.0, which seems to create all needed files as individual scripts, as opposed to all compiled in a single .dll.
     
  47. mariobarreiro

    mariobarreiro

    Joined:
    Oct 10, 2016
    Posts:
    3
    Hi Georges!

    We are having an issue in IOS. We have posted it on github https://github.com/xanathar/moonsharp/issues/165

    Basically everything works fine until we try to release a version. We upload the app on release mode to iTunes and LUA scripts don't work. If we upload it on dev mode it works. It shows the following error:

    "ScriptRunTimeException: Can not convert clr type System.MonoType"

    Any clue? Thanks in advance for your time.
    Mario
     
  48. georgesdimitrov

    georgesdimitrov

    Joined:
    Feb 4, 2013
    Posts:
    50
    Hi mariobarreiro, I contacted the Moonsharp developer to ask him, he answered on github, asking for a bit more information. I hope you can resolve that with him if it's a moonsharp issue, I don't know what may be causing the issue on my end, and I don't see why something would work in Dev but not release... On my end, I checked that any reflection calls that I do are allowed on iOS.
     
  49. mariobarreiro

    mariobarreiro

    Joined:
    Oct 10, 2016
    Posts:
    3
    Hi Georges, thanks for your answer.

    Basically we did the tutorial with LUA, which accesses C# classes. We guess that Apple doesn't like that, because without that, LUA is perfectly working.

    Mario
     
  50. Goonomi

    Goonomi

    Joined:
    Mar 13, 2017
    Posts:
    16
    Hi,

    i have a quick question. If i had a script in Unity with a function called DebugTest(), how would i run this function via the .lua file?

    Sorry if you already answered the question with

    but im just starting with the external scripting stuff and i'm having a hard time getting this to work. If you could provide a short example, i would be very thankful.