游戏王残局简化版

Annotation For single_doc/lua_lib/u8_to_a.lua
Login

Annotation For single_doc/lua_lib/u8_to_a.lua

Origin for each line in single_doc/lua_lib/u8_to_a.lua from check-in 60c256f91b:

60c256f91b 2024-06-27  顽雨沉风: local ffi = require("ffi")
60c256f91b 2024-06-27  顽雨沉风: local s = {}
60c256f91b 2024-06-27  顽雨沉风: ffi.cdef([[
60c256f91b 2024-06-27  顽雨沉风: typedef unsigned int UINT;
60c256f91b 2024-06-27  顽雨沉风: typedef unsigned long DWORD;
60c256f91b 2024-06-27  顽雨沉风: typedef wchar_t WCHAR;
60c256f91b 2024-06-27  顽雨沉风: typedef WCHAR* LPWSTR;
60c256f91b 2024-06-27  顽雨沉风: typedef wchar_t* LPCWCH;
60c256f91b 2024-06-27  顽雨沉风: typedef char CHAR;
60c256f91b 2024-06-27  顽雨沉风: typedef CHAR* LPSTR;
60c256f91b 2024-06-27  顽雨沉风: typedef const char* LPCCH;
60c256f91b 2024-06-27  顽雨沉风: typedef int BOOL;
60c256f91b 2024-06-27  顽雨沉风: typedef BOOL* LPBOOL;
60c256f91b 2024-06-27  顽雨沉风: int MultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCCH lpMultiByteStr, int cbMultiByte, LPWSTR lpWideCharStr, int cchWideChar);
60c256f91b 2024-06-27  顽雨沉风: int WideCharToMultiByte(UINT CodePage, DWORD dwFlags, LPCWCH lpWideCharStr, int cchWideChar, LPSTR lpMultiByteStr, int cchMultiByte, LPCCH lpDefaultChar, LPBOOL pfUsedDefaultChar);
60c256f91b 2024-06-27  顽雨沉风: ]])
60c256f91b 2024-06-27  顽雨沉风: s.CP_ACP = 0
60c256f91b 2024-06-27  顽雨沉风: s.CP_UTF8 = 65001
60c256f91b 2024-06-27  顽雨沉风: --~ 算机_基统_窗群
60c256f91b 2024-06-27  顽雨沉风: function s.m2w(input, u1)
60c256f91b 2024-06-27  顽雨沉风:   local wlen = ffi.C.MultiByteToWideChar(u1 or s.CP_ACP, 0, input, #input, nil, 0)
60c256f91b 2024-06-27  顽雨沉风:   local wstr = ffi.new("wchar_t[?]", wlen + 1)
60c256f91b 2024-06-27  顽雨沉风:   ffi.C.MultiByteToWideChar(u1 or s.CP_ACP, 0, input, #input, wstr, wlen)
60c256f91b 2024-06-27  顽雨沉风:   return wstr, wlen
60c256f91b 2024-06-27  顽雨沉风: end
60c256f91b 2024-06-27  顽雨沉风: function s.w2m(wstr, wlen, u1)
60c256f91b 2024-06-27  顽雨沉风:   local len = ffi.C.WideCharToMultiByte(u1 or s.CP_ACP, 0, wstr, wlen or -1, nil, 0, nil, nil)
60c256f91b 2024-06-27  顽雨沉风:   local str = ffi.new("char[?]", len)
60c256f91b 2024-06-27  顽雨沉风:   ffi.C.WideCharToMultiByte(u1 or s.CP_ACP, 0, wstr, wlen or -1, str, len, nil, nil)
60c256f91b 2024-06-27  顽雨沉风:   return ffi.string(str, len)
60c256f91b 2024-06-27  顽雨沉风: end
60c256f91b 2024-06-27  顽雨沉风: --~ 通用大字集_八位
60c256f91b 2024-06-27  顽雨沉风: function s.u8_to_a(input)
60c256f91b 2024-06-27  顽雨沉风:   return s.w2m(s.m2w(input, s.CP_UTF8))
60c256f91b 2024-06-27  顽雨沉风: end
60c256f91b 2024-06-27  顽雨沉风: function s.a_to_u8(input)
60c256f91b 2024-06-27  顽雨沉风:   local h1, h2 = s.m2w(input)
60c256f91b 2024-06-27  顽雨沉风:   return s.w2m(h1, h2, s.CP_UTF8)
60c256f91b 2024-06-27  顽雨沉风: end
60c256f91b 2024-06-27  顽雨沉风: return s