【问题标题】:Passing a C# object into a lua function with moonsharp.使用 moonsharp 将 C# 对象传递给 lua 函数。
【发布时间】:2017-07-21 21:47:00
【问题描述】:

我在 Unity3d 中使用 Moonsharp 时遇到问题。我正在尝试传递“AppletMessage”对象:

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

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

进入 lua 中的一个函数,我不知道该怎么做。 我目前正在做的是这样的:

//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});

当它尝试调用函数并传入 AppletMessage 时,这给了我来自 applet 类的错误:

cannot access field  of userdata<AppletMessage>

【问题讨论】:

    标签: c# unity3d lua mono moonsharp


    【解决方案1】:

    您是否在游戏开始时添加了Moonsharp.Interpreter.UserData.RegisterAssembly();?你需要这个来检测[MoonSharpUserData]标签并使其正常工作。

    【讨论】:

    • 如果您不确定这是答案,您应该将其作为评论(您需要 10 分)
    • 你必须正确回答一个问题。我们都赢得了特权
    • 好的,我试试!但我认为我的回答是正确的,至少从我使用 Moonsharp 的经验来看,这似乎是最可能的错误原因。
    猜你喜欢
    • 1970-01-01
    • 2019-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-25
    • 2015-08-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多