美文网首页
XLua使用过程中的异常记录

XLua使用过程中的异常记录

作者: Kim_9527 | 来源:发表于2017-05-10 16:09 被阅读665次

记录腾讯的开源Lua计划XLua的使用过程中遇到的各种异常/解决记录

1.LuaException: c# exception:Non-static method requires a target.,stack: at System.Reflection.MonoMethod.Invoke
调用非静态方法的时候要使用‘:’,而不能使用‘.’

    //Test.class
    public class Test {
      public void PrintStr()
      {
            Debug.Log("...");
       }
    }
--Test.lua
  function start()
    //--CS.Test().PrintStr()<-Wrong
    CS.Test():PrintStr();
  end

InvalidCastException: This delegate must add to CSharpCallLua: System.Action
可能造成的因素之一:代码还没有生成
解决办法:XLua->Generate Code
可能造成的因素之二:没有将用到的类型加到CSharpCallLua编译列表中

public static List<Type> CSharpCallLua = new List<Type>()
    {
        typeof(Action),
        //添加需要使用的泛型
        typeof(Action<bool>),
        typeof(UnityAction),
    };

相关文章

网友评论

      本文标题:XLua使用过程中的异常记录

      本文链接:https://www.haomeiwen.com/subject/lddgtxtx.html