游戏王残局简化版

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

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

Origin for each line in 残局文料/lib/u8_to_a.lua from check-in a2e76b01c2:

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