Author Topic: Lua-Iconv  (Read 2588 times)

0 Members and 1 Guest are viewing this topic.

Offline PPK

  • Administrator
  • Emperor
  • *****
  • Posts: 1 481
  • Karma: +209/-22
  • PtokaX developer
Lua-Iconv
« 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:
Code: [Select]
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 ;)
« Last Edit: 08 May, 2012, 18:22:05 by PPK »
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

PtokaX forum

Lua-Iconv
« on: 09 April, 2012, 16:45:11 »

Offline PPK

  • Administrator
  • Emperor
  • *****
  • Posts: 1 481
  • Karma: +209/-22
  • PtokaX developer
Re: Lua-Iconv 6
« Reply #1 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

Code: [Select]
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
« Last Edit: 09 May, 2012, 23:06:55 by PPK »
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

Offline PPK

  • Administrator
  • Emperor
  • *****
  • Posts: 1 481
  • Karma: +209/-22
  • PtokaX developer
Re: Lua-Iconv
« Reply #2 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:
Code: [Select]
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 ;)
« Last Edit: 17 June, 2012, 18:14:27 by PPK »
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

PtokaX forum

Re: Lua-Iconv
« Reply #2 on: 08 May, 2012, 18:20:01 »