|
|
|
@ -4390,112 +4390,14 @@ script_update = { |
|
|
|
|
end |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-->> SCRIPT UTF-8 |
|
|
|
|
_utf8 = load([=[return function(utf8_func, in_encoding, out_encoding); |
|
|
|
|
if encoding == nil then; |
|
|
|
|
encoding = require("encoding"); |
|
|
|
|
encoding.default = "CP1251"; |
|
|
|
|
u8 = encoding.UTF8; |
|
|
|
|
end; |
|
|
|
|
if type(utf8_func) ~= "table" then; |
|
|
|
|
return false; |
|
|
|
|
end; |
|
|
|
|
if AnsiToUtf8 == nil or Utf8ToAnsi == nil then; |
|
|
|
|
AnsiToUtf8 = function(text); |
|
|
|
|
return u8(text); |
|
|
|
|
end; |
|
|
|
|
Utf8ToAnsi = function(text); |
|
|
|
|
return u8:decode(text); |
|
|
|
|
end; |
|
|
|
|
end; |
|
|
|
|
if _UTF8_FUNCTION_SAVE == nil then; |
|
|
|
|
_UTF8_FUNCTION_SAVE = {}; |
|
|
|
|
end; |
|
|
|
|
local change_var = "_G"; |
|
|
|
|
for s = 1, #utf8_func do; |
|
|
|
|
change_var = string.format('%s["%s"]', change_var, utf8_func[s]); |
|
|
|
|
end; |
|
|
|
|
if _UTF8_FUNCTION_SAVE[change_var] == nil then |
|
|
|
|
_UTF8_FUNCTION = function(...); |
|
|
|
|
local pack = table.pack(...); |
|
|
|
|
for i = 1, pack.n do; |
|
|
|
|
if type(pack[i]) == "string" and in_encoding ~= nil and (in_encoding == "AnsiToUtf8" or in_encoding == "Utf8ToAnsi") then; |
|
|
|
|
pack[i] = _G[in_encoding](pack[i]); |
|
|
|
|
end; |
|
|
|
|
end; |
|
|
|
|
local unpacked = {_UTF8_FUNCTION_SAVE[change_var](table.unpack(pack))}; |
|
|
|
|
for i = 1, #unpacked do; |
|
|
|
|
if type(unpacked[i]) == "string" and out_encoding ~= nil and (out_encoding == "AnsiToUtf8" or out_encoding == "Utf8ToAnsi") then; |
|
|
|
|
unpacked[i] = _G[out_encoding](unpacked[i]); |
|
|
|
|
end; |
|
|
|
|
end; |
|
|
|
|
return table.unpack(unpacked); |
|
|
|
|
end; |
|
|
|
|
local text = string.format("_UTF8_FUNCTION_SAVE['%s'] = %s; %s = _UTF8_FUNCTION;", change_var, change_var, change_var); |
|
|
|
|
load(text)(); |
|
|
|
|
_UTF8_FUNCTION = nil; |
|
|
|
|
end; |
|
|
|
|
return true; |
|
|
|
|
end]=]) |
|
|
|
|
|
|
|
|
|
function utf8(...) |
|
|
|
|
local pack = table.pack(...); |
|
|
|
|
pcall(_utf8(), table.unpack(pack)) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
-- utf8 = function(utf8_func, in_encoding, out_encoding); if _G["encoding"] == nil then; _G["encoding"] = require("encoding"); _G["encoding"]["default"] = "CP1251"; _G["u8"] = _G["encoding"]["UTF8"]; end; if type(utf8_func) ~= "table" then; return false; end; if _G["AnsiToUtf8"] == nil or _G["Utf8ToAnsi"] == nil then; _G["AnsiToUtf8"] = function(text); return _G["u8"](text); end; _G["Utf8ToAnsi"] = function(text); return _G["u8"]:decode(text); end; end; if _G["_UTF8_FUNCTION_SAVE"] == nil then; _G["_UTF8_FUNCTION_SAVE"] = {}; end; local change_var = "_G"; for s = 1, #utf8_func do; change_var = string.format('%s["%s"]', change_var, utf8_func[s]); end; if _G["_UTF8_FUNCTION_SAVE"][change_var] == nil then _G["_UTF8_FUNCTION"] = function(...); local pack = table.pack(...); for i = 1, pack.n do; if type(pack[i]) == "string" and in_encoding ~= nil and (in_encoding == "AnsiToUtf8" or in_encoding == "Utf8ToAnsi") then; pack[i] = _G[in_encoding](pack[i]); end; end; local unpacked = {_G["_UTF8_FUNCTION_SAVE"][change_var](table.unpack(pack))}; for i = 1, #unpacked do; if type(unpacked[i]) == "string" and out_encoding ~= nil and (out_encoding == "AnsiToUtf8" or out_encoding == "Utf8ToAnsi") then; unpacked[i] = _G[out_encoding](unpacked[i]); end; end; return table.unpack(unpacked); end; local text = string.format("_G['_UTF8_FUNCTION_SAVE']['%s'] = %s; %s = _G['_UTF8_FUNCTION'];", change_var, change_var, change_var); load(text)(); _G["_UTF8_FUNCTION"] = nil; end; return true; end |
|
|
|
|
|
|
|
|
|
-- utf8 = function(utf8_func, in_encoding, out_encoding); |
|
|
|
|
-- if _G["encoding"] == nil then; |
|
|
|
|
-- _G["encoding"] = require("encoding"); |
|
|
|
|
-- _G["encoding"]["default"] = "CP1251"; |
|
|
|
|
-- _G["u8"] = _G["encoding"]["UTF8"]; |
|
|
|
|
-- end; |
|
|
|
|
-- if type(utf8_func) ~= "table" then; |
|
|
|
|
-- return false; |
|
|
|
|
-- end; |
|
|
|
|
-- if _G["AnsiToUtf8"] == nil or _G["Utf8ToAnsi"] == nil then; |
|
|
|
|
-- _G["AnsiToUtf8"] = function(text); |
|
|
|
|
-- return _G["u8"](text); |
|
|
|
|
-- end; |
|
|
|
|
-- _G["Utf8ToAnsi"] = function(text); |
|
|
|
|
-- return _G["u8"]:decode(text); |
|
|
|
|
-- end; |
|
|
|
|
-- end; |
|
|
|
|
-- if _G["_UTF8_FUNCTION_SAVE"] == nil then; |
|
|
|
|
-- _G["_UTF8_FUNCTION_SAVE"] = {}; |
|
|
|
|
-- end; |
|
|
|
|
-- local change_var = "_G"; |
|
|
|
|
-- for s = 1, #utf8_func do; |
|
|
|
|
-- change_var = string.format('%s["%s"]', change_var, utf8_func[s]); |
|
|
|
|
-- end; |
|
|
|
|
-- if _G["_UTF8_FUNCTION_SAVE"][change_var] == nil then |
|
|
|
|
-- _G["_UTF8_FUNCTION"] = function(...); |
|
|
|
|
-- local pack = table.pack(...); |
|
|
|
|
-- for i = 1, pack.n do; |
|
|
|
|
-- if type(pack[i]) == "string" and in_encoding ~= nil and (in_encoding == "AnsiToUtf8" or in_encoding == "Utf8ToAnsi") then; |
|
|
|
|
-- pack[i] = _G[in_encoding](pack[i]); |
|
|
|
|
-- end; |
|
|
|
|
-- end; |
|
|
|
|
-- local unpacked = {_G["_UTF8_FUNCTION_SAVE"][change_var](table.unpack(pack))}; |
|
|
|
|
-- for i = 1, #unpacked do; |
|
|
|
|
-- if type(unpacked[i]) == "string" and out_encoding ~= nil and (out_encoding == "AnsiToUtf8" or out_encoding == "Utf8ToAnsi") then; |
|
|
|
|
-- unpacked[i] = _G[out_encoding](unpacked[i]); |
|
|
|
|
-- end; |
|
|
|
|
-- end; |
|
|
|
|
-- return table.unpack(unpacked); |
|
|
|
|
-- end; |
|
|
|
|
-- local text = string.format("_G['_UTF8_FUNCTION_SAVE']['%s'] = %s; %s = _G['_UTF8_FUNCTION'];", change_var, change_var, change_var); |
|
|
|
|
-- load(text)(); |
|
|
|
|
-- _G["_UTF8_FUNCTION"] = nil; |
|
|
|
|
-- end; |
|
|
|
|
-- return true; |
|
|
|
|
-- end |
|
|
|
|
|
|
|
|
|
-->> utf8(table path, incoming variables encoding, outcoming variables encoding) |
|
|
|
|
-->> table path example { "sampev", "onShowDialog" } |
|
|
|
|
-->> encoding options nil | AnsiToUtf8 | Utf8ToAnsi |
|
|
|
|
_utf8 = load([=[return function(utf8_func, in_encoding, out_encoding); if encoding == nil then; encoding = require("encoding"); encoding.default = "CP1251"; u8 = encoding.UTF8; end; if type(utf8_func) ~= "table" then; return false; end; if AnsiToUtf8 == nil or Utf8ToAnsi == nil then; AnsiToUtf8 = function(text); return u8(text); end; Utf8ToAnsi = function(text); return u8:decode(text); end; end; if _UTF8_FUNCTION_SAVE == nil then; _UTF8_FUNCTION_SAVE = {}; end; local change_var = "_G"; for s = 1, #utf8_func do; change_var = string.format('%s["%s"]', change_var, utf8_func[s]); end; if _UTF8_FUNCTION_SAVE[change_var] == nil then _UTF8_FUNCTION = function(...); local pack = table.pack(...); for i = 1, pack.n do; if type(pack[i]) == "string" and in_encoding ~= nil and (in_encoding == "AnsiToUtf8" or in_encoding == "Utf8ToAnsi") then; pack[i] = _G[in_encoding](pack[i]); end; end; local unpacked = {_UTF8_FUNCTION_SAVE[change_var](table.unpack(pack))}; for i = 1, #unpacked do; if type(unpacked[i]) == "string" and out_encoding ~= nil and (out_encoding == "AnsiToUtf8" or out_encoding == "Utf8ToAnsi") then; unpacked[i] = _G[out_encoding](unpacked[i]); end; end; return table.unpack(unpacked); end; local text = string.format("_UTF8_FUNCTION_SAVE['%s'] = %s; %s = _UTF8_FUNCTION;", change_var, change_var, change_var); load(text)(); _UTF8_FUNCTION = nil; end; return true; end]=]) |
|
|
|
|
function utf8(...) |
|
|
|
|
pcall(_utf8(), ...) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
utf8({ "sampShowDialog" }, "Utf8ToAnsi") |
|
|
|
|
utf8({ "sampSendChat" }, "Utf8ToAnsi") |
|
|
|
|