游戏王残局简化版

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

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

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

97579aac1b 2024-01-23  顽雨沉风: local ffi = require("ffi")
9973312896 2024-01-23  顽雨沉风: local d_4 = {}
97579aac1b 2024-01-23  顽雨沉风: ffi.cdef([[
97579aac1b 2024-01-23  顽雨沉风: typedef unsigned int UINT;
97579aac1b 2024-01-23  顽雨沉风: typedef unsigned long DWORD;
97579aac1b 2024-01-23  顽雨沉风: typedef wchar_t WCHAR;
97579aac1b 2024-01-23  顽雨沉风: typedef WCHAR* LPWSTR;
97579aac1b 2024-01-23  顽雨沉风: typedef wchar_t* LPCWCH;
97579aac1b 2024-01-23  顽雨沉风: typedef char CHAR;
97579aac1b 2024-01-23  顽雨沉风: typedef CHAR* LPSTR;
97579aac1b 2024-01-23  顽雨沉风: typedef const char* LPCCH;
97579aac1b 2024-01-23  顽雨沉风: typedef int BOOL;
97579aac1b 2024-01-23  顽雨沉风: typedef BOOL* LPBOOL;
97579aac1b 2024-01-23  顽雨沉风: int MultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCCH lpMultiByteStr, int cbMultiByte, LPWSTR lpWideCharStr, int cchWideChar);
97579aac1b 2024-01-23  顽雨沉风: int WideCharToMultiByte(UINT CodePage, DWORD dwFlags, LPCWCH lpWideCharStr, int cchWideChar, LPSTR lpMultiByteStr, int cchMultiByte, LPCCH lpDefaultChar, LPBOOL pfUsedDefaultChar);
97579aac1b 2024-01-23  顽雨沉风: ]])
9973312896 2024-01-23  顽雨沉风: d_4.CP_ACP = 0
9973312896 2024-01-23  顽雨沉风: d_4.CP_UTF8 = 65001
9973312896 2024-01-23  顽雨沉风: function d_4.m2w(input, o1)
9973312896 2024-01-23  顽雨沉风:   local wlen = ffi.C.MultiByteToWideChar(o1 or d_4.CP_ACP, 0, input, #input, nil, 0)
97579aac1b 2024-01-23  顽雨沉风:   local wstr = ffi.new("wchar_t[?]", wlen + 1)
9973312896 2024-01-23  顽雨沉风:   ffi.C.MultiByteToWideChar(o1 or d_4.CP_ACP, 0, input, #input, wstr, wlen)
97579aac1b 2024-01-23  顽雨沉风:   return wstr, wlen
97579aac1b 2024-01-23  顽雨沉风:   end
9973312896 2024-01-23  顽雨沉风: function d_4.w2m(wstr, wlen, o1)
9973312896 2024-01-23  顽雨沉风:   local len = ffi.C.WideCharToMultiByte(o1 or d_4.CP_ACP, 0, wstr, wlen or -1, nil, 0, nil, nil)
97579aac1b 2024-01-23  顽雨沉风:   local str = ffi.new("char[?]", len)
9973312896 2024-01-23  顽雨沉风:   ffi.C.WideCharToMultiByte(o1 or d_4.CP_ACP, 0, wstr, wlen or -1, str, len, nil, nil)
97579aac1b 2024-01-23  顽雨沉风:   return ffi.string(str, len)
97579aac1b 2024-01-23  顽雨沉风:   end
9973312896 2024-01-23  顽雨沉风: function d_4.u8_to_a(input)
9973312896 2024-01-23  顽雨沉风:   return d_4.w2m(d_4.m2w(input, d_4.CP_UTF8))
9973312896 2024-01-23  顽雨沉风:   end
9973312896 2024-01-23  顽雨沉风: function d_4.a_to_u8(input)
9973312896 2024-01-23  顽雨沉风:   local k1, k2 = d_4.m2w(input)
9973312896 2024-01-23  顽雨沉风:   return d_4.w2m(k1, k2, d_4.CP_UTF8)
9973312896 2024-01-23  顽雨沉风:   end
9973312896 2024-01-23  顽雨沉风: return d_4