Tencent / xLua

xLua is a lua programming solution for C# ( Unity, .Net, Mono) , it supports android, ios, windows, linux, osx, etc.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

无法调试带中文命名Lua文件

gavin-wuz opened this issue · comments

Lua命名为:Demo中文.lua时不能调试;
在实际项目中会存在有中文命名场景,希望能支持带中文命名的方式调试;

2023 08 17 a48b155b1759fc2823e3e8b0b97af0bf

对比U3D项目,是可以正常调试,如下:
2023 08 17 6c1884a51bf724dcea623892fb89a62c

  • Demo中文.lua
LuaPanda.start("127.0.0.1",8818)
LuaPanda.BP()

print("版本:".._VERSION)
local info = debug.getinfo(1, 'S')
for k,v in pairs(info) do
    if k == 'source' then
        print('source:'..v)
    end
end
  • 测试项目是c#的控制台程序,引用XLUA后,通过LuaPanda在VS CODE中调试,通过debug.getInfo() 获取的source是乱码,导致无法找到对应的Demo中文.lua
  • 而把项目迁移到U3d工程中,通过debug.getInfo() 获取的source没有乱码,又可以正常调试;

环境

  • 操作系统是 window10
  • Lua 5.1

以下排查的情况
1、可能是LuaPanda问题,更换为IDEA+emmy_core 作为Server,控制台程序xlua为client,发现获取的source也是乱码;
2、Lua文件编码问题,统一改为UTF-8,也无法解决;
3、Lua文件编码与Xlua的C#源码统一改为GBK编码,也无法解决;
4、不调试,直接运行Lua可以正常

Lua ./`Demo中文.lua
版本:Lua 5.1
source:@./demo中文.lua

注:下面是测试项目源码

已经找到问题,在LuaDLL.cs

       [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
       public static extern int xluaL_loadbuffer(IntPtr L, byte[] buff, int size, string name);

修改为

        [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
        public static extern int xluaL_loadbuffer(IntPtr L, byte[] buff, int size, byte[] names);


        public static int xluaL_loadbuffer(IntPtr L, byte[] buff, int size, string name)
        {
            var names = Encoding.UTF8.GetBytes(name);//FIX: 中文名称乱码,需要转为byte[]给LUA
            return xluaL_loadbuffer(L, buff, size, names);
        }