Created
April 30, 2022 07:05
-
-
Save zr-tex8r/eb20d1a3b15e28641701950c5e0bcd8c to your computer and use it in GitHub Desktop.
なんかアレなやつ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local ffi = require("ffi") | |
ffi.cdef[[ | |
int GetLocaleInfoEx( | |
const wchar_t *lpLocaleName, | |
unsigned long LCType, | |
wchar_t *lpLCData, | |
int cchData | |
); | |
]] | |
function to_wstr(str) | |
local out = ffi.new("wchar_t[?]", #str+1) | |
for i = 1, #str do out[i-1] = str:byte(i) end | |
return out | |
end | |
function from_wstr(wstr, len) | |
local cs = {} | |
for i = 1, len do cs[i] = wstr[i-1] end | |
return string.char(table.unpack(cs)) | |
end | |
function current_lang() | |
local res = ffi.new("wchar_t[?]", 16) | |
local rlen = ffi.C.GetLocaleInfoEx(nil, 3, res, 16) | |
if rlen == 0 then return end | |
local clcode = from_wstr(res, rlen) | |
print("current language = "..clcode) | |
local qry = ffi.new("wchar_t[?]", 3) | |
for c1 = 97, 122 do for c2 = 97, 122 do | |
qry[0], qry[1] = c1, c2 | |
rlen = ffi.C.GetLocaleInfoEx(qry, 3, res, 16) | |
local code = from_wstr(res, rlen) | |
if clcode == code then | |
print("two-letter code = "..string.char(c1, c2)) | |
end | |
end end | |
end | |
current_lang() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment