我在 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/