游戏王残局简化版

Annotation For 残局文料/lua_lib/u8_to_a.lua
Login

Annotation For 残局文料/lua_lib/u8_to_a.lua

Origin for each line in 残局文料/lua_lib/u8_to_a.lua from check-in 7f8375e5c1:

5e8e495c56 2024-01-30    1: local ffi = require("ffi")
5e8e495c56 2024-01-30    2: local d_4 = {}
5e8e495c56 2024-01-30    3: ffi.cdef([[
5e8e495c56 2024-01-30    4: typedef unsigned int UINT;
5e8e495c56 2024-01-30    5: typedef unsigned long DWORD;
5e8e495c56 2024-01-30    6: typedef wchar_t WCHAR;
5e8e495c56 2024-01-30    7: typedef WCHAR* LPWSTR;
5e8e495c56 2024-01-30    8: typedef wchar_t* LPCWCH;
5e8e495c56 2024-01-30    9: typedef char CHAR;
5e8e495c56 2024-01-30   10: typedef CHAR* LPSTR;
5e8e495c56 2024-01-30   11: typedef const char* LPCCH;
5e8e495c56 2024-01-30   12: typedef int BOOL;
5e8e495c56 2024-01-30   13: typedef BOOL* LPBOOL;
5e8e495c56 2024-01-30   14: int MultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCCH lpMultiByteStr, int cbMultiByte, LPWSTR lpWideCharStr, int cchWideChar);
5e8e495c56 2024-01-30   15: int WideCharToMultiByte(UINT CodePage, DWORD dwFlags, LPCWCH lpWideCharStr, int cchWideChar, LPSTR lpMultiByteStr, int cchMultiByte, LPCCH lpDefaultChar, LPBOOL pfUsedDefaultChar);
5e8e495c56 2024-01-30   16: ]])
5e8e495c56 2024-01-30   17: d_4.CP_ACP = 0
5e8e495c56 2024-01-30   18: d_4.CP_UTF8 = 65001
5e8e495c56 2024-01-30   19: --~ 算机_基统_窗群
5e8e495c56 2024-01-30   20: function d_4.m2w(input, o1)
7f8375e5c1 2024-02-13   21:   local wlen = ffi.C.MultiByteToWideChar(o1 or d_4.CP_ACP, 0, input, #input, nil, 0)
7f8375e5c1 2024-02-13   22:   local wstr = ffi.new("wchar_t[?]", wlen + 1)
7f8375e5c1 2024-02-13   23:   ffi.C.MultiByteToWideChar(o1 or d_4.CP_ACP, 0, input, #input, wstr, wlen)
7f8375e5c1 2024-02-13   24:   return wstr, wlen
5e8e495c56 2024-01-30   25: end
5e8e495c56 2024-01-30   26: function d_4.w2m(wstr, wlen, o1)
7f8375e5c1 2024-02-13   27:   local len = ffi.C.WideCharToMultiByte(o1 or d_4.CP_ACP, 0, wstr, wlen or -1, nil, 0, nil, nil)
7f8375e5c1 2024-02-13   28:   local str = ffi.new("char[?]", len)
7f8375e5c1 2024-02-13   29:   ffi.C.WideCharToMultiByte(o1 or d_4.CP_ACP, 0, wstr, wlen or -1, str, len, nil, nil)
7f8375e5c1 2024-02-13   30:   return ffi.string(str, len)
5e8e495c56 2024-01-30   31: end
5e8e495c56 2024-01-30   32: --~ 通用大字集_八位
5e8e495c56 2024-01-30   33: function d_4.u8_to_a(input)
7f8375e5c1 2024-02-13   34:   return d_4.w2m(d_4.m2w(input, d_4.CP_UTF8))
5e8e495c56 2024-01-30   35: end
5e8e495c56 2024-01-30   36: function d_4.a_to_u8(input)
7f8375e5c1 2024-02-13   37:   local k1, k2 = d_4.m2w(input)
7f8375e5c1 2024-02-13   38:   return d_4.w2m(k1, k2, d_4.CP_UTF8)
5e8e495c56 2024-01-30   39: end
5e8e495c56 2024-01-30   40: return d_4