Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
gavin-wuz opened this issue Aug 17, 2023 · 1 comment
Closed

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

gavin-wuz opened this issue Aug 17, 2023 · 1 comment

Comments

@gavin-wuz
Copy link

gavin-wuz commented Aug 17, 2023

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

注:下面是测试项目源码

@gavin-wuz
Copy link
Author

已经找到问题,在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);
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant