5

I'm having issues using Moonsharp in Unity3d. I'm trying to pass 'AppletMessage' objects:

[MoonSharpUserData]
public class AppletMessage {
    public string Name;
    public string[] Args;

    public AppletMessage(string _name, string[] _args) {
        Name = _name;
        Args = _args;
    }
}

into a function in lua and I'm not sure how to do that. What I'm currently doing is this:

//In a start function
UserData.RegisterType<AppletMessage>();

//Later on, after popping the latest message from a stack as 'LatestMessage'
result = applet.Call( applet.Globals["OnCatchMessage"],new AppletMessage[] {LatestMessage});

this is giving me this error coming from the applet class when it tries to call the function and pass the AppletMessage in:

cannot access field  of userdata<AppletMessage>
T--
  • 53
  • 6

1 Answers1

1

Did you add Moonsharp.Interpreter.UserData.RegisterAssembly(); when your game starts? You need this to detect and make the [MoonSharpUserData] tags work properly.

  • 1
    if you are not sure this is the answer you should make it as a comment (you need 10 points for that) – Ibo Aug 05 '18 at 05:11
  • you have to answer one question correctly. We all earned the privileges – Ibo Aug 05 '18 at 09:09
  • Ok, I'll try! But I think my answer is correct, at least from my experience with Moonsharp that seems to be the most probable cause of the error. – Pedro Medeiros Aug 06 '18 at 04:01