c# - 使用 moonsharp 将 C# 对象传递到 lua 函数中。

标签 c# unity3d lua mono moonsharp

我在 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});

当 applet 类尝试调用该函数并传递 AppletMessage 时,它​​给我这个错误:

cannot access field  of userdata<AppletMessage>

最佳答案

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

关于c# - 使用 moonsharp 将 C# 对象传递到 lua 函数中。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42550826/

相关文章:

c# - x :Type not found in user control library

c# - Azure EventHub - 如何删除事件?

colors - 如何在控制台中使用 ANSI 转义序列将斜体或粗体等格式应用于文本?

java - 如何放弃 LuaJ 协程 LuaThread?

c++ - lua_pop 与 lua_remove

c# - Aforge.net 相机捕获并将图像保存到目录

c# - 为什么下拉事件在asp中不起作用

c# - 如何在 Unity 中更改 Material

unity3d - 在 Unity 中调整正交相机的大小

c# - 主线程上的网络请求导致帧率延迟峰值