APSchmidt 发表于 2021-8-13 10:41

Unity-xlua C#侧将byte[]传递lua侧table

一、 Xlua C#侧与lua侧的类型映射关系



基本类型中C#侧 byte[] 对应lua侧的string;复杂类型中LuaTable 对应lua侧的table;
二、 实现

思路:在c#侧将byte[]转LuaTable即可
[*]C#侧:
public LuaTable TestBytes2(){byte[] testbyte = System.Text.Encoding.Default.GetBytes("ab");
      luaTable = luaEnv.NewTable();for(int i =0; i < testbyte.Length; i++){//lua table 下标从1开始的
            luaTable.Set(i +1, testbyte);}return luaTable;}publicbyte[]TestBytes1(){byte[] testbyte = System.Text.Encoding.Default.GetBytes("ab");return testbyte;}
[*]lua侧
function start()print("lua start...")       
        local cube = CS.UnityEngine.GameObject.Find("Cube")
        cubeBehavior = cube:GetComponent(typeof(CS.XLuaTest.LuaBehaviour))
        local tmp1 = cubeBehavior:TestBytes1()print("tmp1 : ", tmp1)
        local tmp2 = cubeBehavior:TestBytes2()print("tmp2 : ", tmp2, tmp2)       
end输出结果截图:



页: [1]
查看完整版本: Unity-xlua C#侧将byte[]传递lua侧table