PtokaX forum

Development Section => Extensions for PtokaX Lua => Topic started by: PPK on 09 April, 2012, 16:45:11

Title: Lua-Iconv
Post by: PPK on 09 April, 2012, 16:45:11
Version for PtokaX 0.4.2.0 build 376 and higher.

Homepage: http://luaforge.net/projects/lua-iconv/

Binary: http://www.PtokaX.org/files/Libs-376/Lua-Iconv-6.7z
Binary x64: http://www.PtokaX.org/files/Libs-376/Lua-Iconv-6-x64.7z
Source: http://www.PtokaX.org/files/Libs-376/Lua-Iconv-6-src.7z

Initializing:

require "iconv"


This will register global iconv, more is in readme 8)

This lib is compatible with PXLua 5.1.5 and PXLua 5.2.0 ;)
Title: Re: Lua-Iconv 6
Post by: PPK on 09 April, 2012, 16:52:07
Example script.
When user country is Russia, Ukraine or Belarus then any his text sent to chat is tested for utf-8 encoding. When text is not in utf-8 then is converted from win-1251 encoding (default on windows) to utf-8  :P


local iconv = require "iconv"

utf8test = nil
cp1251toutf8 = nil

function OnStartup()
    utf8test = iconv.new("utf8", "utf8") -- setup utf-8 encoding checker
    cp1251toutf8 = iconv.new("utf8", "cp1251") -- setup win-1251 to utf-8 converter
end

function ChatArrival(curUser, sData)
    CountryCode = Core.GetUserValue(curUser, 26) -- get user country code

    if CountryCode == nil then -- no country code found, no conversion
        return false
    end

    if CountryCode ~= "RU" and CountryCode ~= "UA" and CountryCode ~= "BY"then -- user is not from Russia, Ukraine or Belarus. no conversion
        return false
    end

   if string.find(SetMan.GetString(29), string.sub(sData, 4+string.len(curUser.sNick), 4+string.len(curUser.sNick)), 1, true) then -- test for hub commands, no conversion
      return false
   end

    nstr, err = utf8test:iconv(sData) -- utf-8 encoding test
    if err ~= nil then
        nstr, err = cp1251toutf8:iconv(sData) -- conversion from win-1251 to utf-8
        if err == nil then
            Core.SendToAll(nstr) -- send converted chat
            UDPDbg.Send(sData) -- send original to udp debug
            return true -- don't process data by hub
        end
    end
end
Title: Re: Lua-Iconv
Post by: PPK on 08 May, 2012, 18:20:01
Lua-iconv 7 for PtokaX 0.4.2.0 build 376 and higher.

Homepage: http://luaforge.net/projects/lua-iconv/

Binary: http://www.PtokaX.org/files/Libs-376/Lua-Iconv-7.7z
Binary x64: http://www.PtokaX.org/files/Libs-376/Lua-Iconv-7-x64.7z
Source: http://www.PtokaX.org/files/Libs-376/Lua-Iconv-7-src.7z

Initializing:

local iconv = require "iconv"


This will create iconv metatable (version 7 no more create global iconv), more is in readme 8)

This lib is compatible with PXLua 5.1.5, 5.2.0 and 5.2.1 ;)